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
echo "usage: lxc-create -n <name> [-f configuration] [-t template] [-h] -- [template_options]"
30
echo "creates a lxc system object."
33
echo "name : name of the container"
34
echo "configuration: lxc configuration"
35
echo "template : lxc-template is an accessible template script"
36
if [ -z $lxc_template ]; then
37
echo "for template-specific help, specify a template, for instance:"
38
echo "lxc-create -t ubuntu -h"
41
type ${templatedir}/lxc-$lxc_template >/dev/null
43
echo "template-specific help follows: (these options follow '--')"
45
${templatedir}/lxc-$lxc_template -h
49
shortoptions='hn:f:t:'
50
longoptions='help,name:,config:,template:'
53
templatedir=@LXCTEMPLATEDIR@
55
getopt=$(getopt -o $shortoptions --longoptions $longoptions -- "$@")
95
if [ -z "$lxc_path" ]; then
96
echo "no configuration path defined !"
100
if [ ! -r $lxc_path ]; then
101
echo "configuration path '$lxc_path' not found"
105
if [ -z "$lxc_name" ]; then
106
echo "no container name specified"
111
if [ "$(id -u)" != "0" ]; then
112
echo "This command has to be run as root"
116
if [ -d "$lxc_path/$lxc_name" ]; then
117
echo "'$lxc_name' already exists"
121
trap "${bindir}/lxc-destroy -n $lxc_name; echo aborted; exit 1" SIGHUP SIGINT SIGTERM
123
mkdir -p $lxc_path/$lxc_name
125
if [ -z "$lxc_config" ]; then
127
echo "No config file specified, using the default config"
128
lxc_config="/etc/lxc/lxc.conf"
131
if [ ! -r "$lxc_config" ]; then
132
echo "'$lxc_config' configuration file not found"
136
cp $lxc_config $lxc_path/$lxc_name/config
138
if [ ! -z $lxc_template ]; then
140
type ${templatedir}/lxc-$lxc_template >/dev/null
141
if [ $? -ne 0 ]; then
142
echo "unknown template '$lxc_template'"
143
${bindir}/lxc-destroy -n $lxc_name
147
${templatedir}/lxc-$lxc_template --path=$lxc_path/$lxc_name --name=$lxc_name $*
148
if [ $? -ne 0 ]; then
149
echo "failed to execute template '$lxc_template'"
150
${bindir}/lxc-destroy -n $lxc_name
154
echo "'$lxc_template' template installed"
157
echo "'$lxc_name' created"