]>
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:'
47 getopt
=$
(getopt
-o $shortoptions --longoptions $longoptions -- "$@")
87 if [ -z "$lxc_name" ]; then
88 echo "no container name specified"
93 if [ "$(id -u)" != "0" ]; then
94 echo "This command has to be run as root"
98 if [ ! -r $lxc_path ]; then
99 echo "no configuration path defined !"
103 if [ -d "$lxc_path/$lxc_name" ]; then
104 echo "'$lxc_name' already exists"
108 trap "lxc-destroy -n $lxc_name; echo aborted; exit 1" SIGHUP SIGINT SIGTERM
110 mkdir
-p $lxc_path/$lxc_name
112 if [ -z "$lxc_config" ]; then
113 touch $lxc_path/$lxc_name/config
115 if [ ! -r "$lxc_config" ]; then
116 echo "'$lxc_config' configuration file not found"
120 cp $lxc_config $lxc_path/$lxc_name/config
123 if [ ! -z $lxc_template ]; then
125 type lxc-
$lxc_template
126 if [ $?
-ne 0 ]; then
127 echo "unknown template '$lxc_template'"
128 lxc-destroy
-n $lxc_name
132 if [ -z "$lxc_config" ]; then
136 echo "Usually the template option is called with a configuration"
137 echo "file option too, mostly to configure the network."
138 echo "eg. lxc-create -n foo -f lxc.conf -t debian"
139 echo "The configuration file is often:"
141 echo "lxc.network.type=macvlan"
142 echo "lxc.network.link=eth0"
143 echo "lxc.network.flags=up"
145 echo "or alternatively:"
147 echo "lxc.network.type=veth"
148 echo "lxc.network.link=br0"
149 echo "lxc.network.flags=up"
151 echo "For more information look at lxc.conf (5)"
153 echo "At this point, I assume you know what you do."
154 echo "Press <enter> to continue ..."
158 lxc-
$lxc_template --path=$lxc_path/$lxc_name --name=$lxc_name
159 if [ $?
-ne 0 ]; then
160 echo "failed to execute template '$lxc_template'"
161 lxc-destroy
-n $lxc_name
165 echo "'$lxc_template' template installed"
168 echo "'$lxc_name' created"