]>
git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/lxc-create.in
4 # lxc: linux Container library
7 # Daniel Lezcano <daniel.lezcano@free.fr>
9 # This library is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public
11 # License as published by the Free Software Foundation; either
12 # version 2.1 of the License, or (at your option) any later version.
14 # This library is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # Lesser General Public License for more details.
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with this library; if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 # This script allows to set or remove the capabilities on the lxc tools.
25 # When the capabilities are set, a non root user can manage the containers.
29 echo "usage: lxc-create -n <name> [-f configuration] [-t template] [-h]"
35 echo "creates a lxc system object."
38 echo "name : name of the container"
39 echo "configuration: lxc configuration"
40 echo "template : lxc-template is an accessible template script"
43 shortoptions
='hn:f:t:'
44 longoptions
='help,name:,config:,template:'
48 getopt
=$
(getopt
-o $shortoptions --longoptions $longoptions -- "$@")
88 if [ -z "$lxc_path" ]; then
89 echo "no configuration path defined !"
93 if [ ! -r $lxc_path ]; then
94 echo "configuration path '$lxc_path' not found"
98 if [ -z "$lxc_name" ]; then
99 echo "no container name specified"
104 if [ "$(id -u)" != "0" ]; then
105 echo "This command has to be run as root"
109 if [ ! -r $lxc_path ]; then
110 echo "no configuration path defined !"
114 if [ -d "$lxc_path/$lxc_name" ]; then
115 echo "'$lxc_name' already exists"
119 trap "${bindir}/lxc-destroy -n $lxc_name; echo aborted; exit 1" SIGHUP SIGINT SIGTERM
121 mkdir
-p $lxc_path/$lxc_name
123 if [ -z "$lxc_config" ]; then
124 touch $lxc_path/$lxc_name/config
126 if [ ! -r "$lxc_config" ]; then
127 echo "'$lxc_config' configuration file not found"
131 cp $lxc_config $lxc_path/$lxc_name/config
134 if [ ! -z $lxc_template ]; then
136 type ${bindir}/lxc-
$lxc_template >/dev
/null
137 if [ $?
-ne 0 ]; then
138 echo "unknown template '$lxc_template'"
139 ${bindir}/lxc-destroy
-n $lxc_name
143 if [ -z "$lxc_config" ]; then
147 echo "Usually the template option is called with a configuration"
148 echo "file option too, mostly to configure the network."
149 echo "eg. lxc-create -n foo -f lxc.conf -t debian"
150 echo "The configuration file is often:"
152 echo "lxc.network.type=macvlan"
153 echo "lxc.network.link=eth0"
154 echo "lxc.network.flags=up"
156 echo "or alternatively:"
158 echo "lxc.network.type=veth"
159 echo "lxc.network.link=br0"
160 echo "lxc.network.flags=up"
162 echo "For more information look at lxc.conf (5)"
164 echo "At this point, I assume you know what you do."
165 echo "Press <enter> to continue ..."
169 ${bindir}/lxc-
$lxc_template --path=$lxc_path/$lxc_name --name=$lxc_name
170 if [ $?
-ne 0 ]; then
171 echo "failed to execute template '$lxc_template'"
172 ${bindir}/lxc-destroy
-n $lxc_name
176 echo "'$lxc_template' template installed"
179 echo "'$lxc_name' created"