-
Notifications
You must be signed in to change notification settings - Fork 0
/
lxc-start-vm
executable file
·52 lines (46 loc) · 1.13 KB
/
lxc-start-vm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
# Note: assuming uid==0 is root -- might break with userns??
if [ "$(id -u)" != "0" ]; then
echo "This script should be run as 'root'"
exit 1
fi
function usage() {
cat << EOF
Usage:
$0 -n <container-name> launches the container with shutdown agent
EOF
# $0 -n <container-name> -a launches the container only, do not launch agent [for scripts]
exit 1
}
container=""
LAUNCH_AGENT=1
while getopts ":an:" opt; do
case $opt in
n)
container=$OPTARG
;;
a)
LAUNCH_AGENT=0
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
;;
:)
echo "Option -$OPTARG requires an argument." >&2
usage
;;
esac
done
[[ ${container} == "" ]] && usage
/usr/bin/logger -t LXC-START "[${container}] Launching container."
/usr/bin/screen -dmS init-${container} /usr/bin/lxc-start -n ${container}
lxc-wait --name=${container} --state=RUNNING
RETVAL=$?
if [ $RETVAL = 0 ]; then
if [ $LAUNCH_AGENT == 1 ]; then
/usr/bin/logger -t LXC-START "[${container}] Launching shutdown agent."
nohup /usr/bin/lxc-shutdown-agent ${container} >/dev/null 2>&1 &
fi
fi
exit $RETVAL