3 function sense_all () {
5 for i in $(lxc-ls -1|sort|uniq); do
6 [ "$(lxc-info -n $i | grep state| awk '{print $2;}' )" == "RUNNING" ] && echo "$i;$(lxc-info -n $i | grep pid | awk '{print $2;}');$(cat /var/lib/lxc/$i/$i.timestamp)" || :
10 function start_all () {
12 for i in $(lxc-ls -1|sort|uniq); do
13 [ "$(lxc-info -n $i | grep state| awk '{print $2;}' )" != "RUNNING" ] && lxc-start -d -n $i || :
14 lxc-wait -n $i -s RUNNING
20 function stop_all () {
22 for i in $(lxc-ls -1|sort|uniq); do
23 [ "$(lxc-info -n $i | grep state| awk '{print $2;}' )" != "STOPPED" ] && lxc-stop -n $i
24 lxc-wait -n $i -s STOPPED
30 function sense_lxc () {
33 [ "$(lxc-info -n $lxc | grep state | awk '{print $2;}')" == "RUNNING" ] && echo "$lxc;$(lxc-info -n $lxc | grep pid | awk '{print $2;}');$(cat /var/lib/lxc/$lxc/$lxc.timestamp)" || :
36 function start_lxc () {
39 [ "$(lxc-info -n $lxc | grep state| awk '{print $2;}' )" != "RUNNING" ] && lxc-start -d -n $lxc ||:
40 lxc-wait -n $lxc -s RUNNING
45 function stop_lxc () {
48 [ "$(lxc-info -n $lxc | grep state| awk '{print $2;}' )" != "STOPPED" ] && lxc-stop -n $lxc
49 lxc-wait -n $lxc -s STOPPED
54 function restart_all () {
60 function restart_lxc () {
67 function destroy_all () {
70 for i in $(lxc-ls -1|sort|uniq); do
76 function destroy_lxc () {
84 echo "Usage: lxc-driver.sh [options]"
86 echo " This command is used to manage and retreive information on existing lxc containers "
87 echo "lxc-driver.sh -c <COMMAND>_all"
88 echo "lxc-driver.sh -c <COMMAND>_lxc -l <LXCNAME>"
89 echo "<COMMAND> in {sense,start,stop,restart,destroy}"
97 while getopts "c:n:" opt ; do
107 sense_all) sense_all ;;
108 start_all) start_all ;;
109 stop_all) stop_all ;;
110 restart_all) restart_all ;;
111 destroy_all) destroy_all ;;
112 sense_lxc) sense_lxc $lxc;;
113 start_lxc) start_lxc $lxc;;
114 stop_lxc) stop_lxc $lxc;;
115 restart_lxc) restart_lxc $lxc;;
116 destroy_lxc) destroy_lxc $lxc;;