39 |
|
|
40 |
lxc_status() { |
lxc_status() { |
41 |
lxc-ls -1 | sort -u | xargs -i lxc-info -n {} | sed "s/'//g" | while read name is status ; do |
lxc-ls -1 | sort -u | xargs -i lxc-info -n {} | sed "s/'//g" | while read name is status ; do |
42 |
on_boot=" " |
boot=" " |
43 |
test -s /var/lib/lxc/$name/on_boot && on_boot="on_boot" |
test -s /var/lib/lxc/$name/on_boot && boot="boot" |
44 |
echo "$name $status $on_boot $(lxc_rootfs $name)" |
echo "$name $status $boot $(lxc_rootfs $name)" |
45 |
done |
done |
46 |
} |
} |
47 |
|
|
73 |
} |
} |
74 |
|
|
75 |
|
|
76 |
|
lxc_log() { |
77 |
|
echo `date +%Y-%m-%dT%H:%M:%S` $* |
78 |
|
} |
79 |
|
|
80 |
|
|
81 |
lxc_kill() { |
lxc_kill() { |
82 |
name=$1 |
name=$1 |
83 |
sig=$2 |
sig=$2 |
87 |
lxc-info -n $name |
lxc-info -n $name |
88 |
exit 1 |
exit 1 |
89 |
fi |
fi |
90 |
echo "$name kill $sig $init_pid" |
lxc_log "$name kill $sig $init_pid" |
91 |
/bin/kill $sig $init_pid |
/bin/kill $sig $init_pid |
92 |
} |
} |
93 |
|
|
94 |
lxc_stop() { |
lxc_stop() { |
95 |
|
lxc_log "$name stop" |
96 |
lxc_kill $name -SIGPWR |
lxc_kill $name -SIGPWR |
97 |
lxc-wait -n $name -s STOPPED |
lxc-wait -n $name -s STOPPED |
98 |
|
lxc_log "$name stoped" |
99 |
# rm -f /var/lib/lxc/${name}/on_boot |
# rm -f /var/lib/lxc/${name}/on_boot |
100 |
} |
} |
101 |
|
|
104 |
name=$1 |
name=$1 |
105 |
|
|
106 |
if ! lxc-info -n $name | grep RUNNING ; then |
if ! lxc-info -n $name | grep RUNNING ; then |
107 |
echo "$name start" |
lxc_log "$name start" |
108 |
lxc-start -n $name -o /tmp/${name}.log -d |
lxc-start -n $name -o /tmp/${name}.log -d |
109 |
lxc-wait -n $name -s RUNNING |
lxc-wait -n $name -s RUNNING |
110 |
lxc-info -n $name |
lxc-info -n $name |
112 |
fi |
fi |
113 |
} |
} |
114 |
|
|
|
lxc_log() { |
|
|
echo `date +%Y-%m-%dT%H:%M:%S` $* |
|
|
} |
|
|
|
|
115 |
lxc_watchdog() { |
lxc_watchdog() { |
116 |
name=$1 |
name=$1 |
117 |
rootfs=$(lxc_rootfs $1) |
rootfs=$(lxc_rootfs $1) |
155 |
inotifywait -qqt 300 ${vps_utmp} |
inotifywait -qqt 300 ${vps_utmp} |
156 |
done |
done |
157 |
|
|
158 |
lxc_log "$name exited" |
lxc_log "$name watchdog exited" |
159 |
|
|
160 |
} |
} |
161 |
|
|
203 |
} |
} |
204 |
|
|
205 |
command=$1 |
command=$1 |
206 |
|
shift |
207 |
|
|
208 |
test "$command" = "status" && lxc_status && exit |
test "$command" = "status" && lxc_status && exit |
209 |
|
|
210 |
if [ -z "$1" ] ; then |
if [ -z "$1" ] ; then |
211 |
ls /var/lib/lxc/*/on_boot | while read path ; do |
ls /var/lib/lxc/*/on_boot | while read path ; do |
212 |
name=`echo $path | cut -d/ -f5` |
name=`echo $path | cut -d/ -f5` |
213 |
command_on_lxc $command $name |
if [ "$command" != "start" -o "$command" = "start" -a -s $path ] ; then |
214 |
|
command_on_lxc $command $name |
215 |
|
else |
216 |
|
echo "# skip $command $name" |
217 |
|
fi |
218 |
done |
done |
219 |
else |
else |
|
shift |
|
220 |
while [ ! -z "$1" ] ; do |
while [ ! -z "$1" ] ; do |
221 |
command_on_lxc $command $1 |
command_on_lxc $command $1 |
222 |
shift |
shift |