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 || :
19 function stop_all () {
21 for i in $(lxc-ls -1|sort|uniq); do
22 [ "$(lxc-info -n $i | grep state| awk '{print $2;}' )" != "STOPPED" ] && lxc-stop -n $i
28 function sense_lxc () {
31 [ "$(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)" || :
34 function start_lxc () {
37 [ "$(lxc-info -n $lxc | grep state| awk '{print $2;}' )" != "RUNNING" ] && lxc-start -d -n $lxc ||:
42 function stop_lxc () {
45 [ "$(lxc-info -n $lxc | grep state| awk '{print $2;}' )" != "STOPPED" ] && lxc-stop -n $lxc
50 function restart_all () {
56 function restart_lxc () {
63 function destroy_all () {
66 for i in $(lxc-ls -1|sort|uniq); do
72 function destroy_lxc () {
80 echo "Usage: lxc-driver.sh [options]"
82 echo " This command is used to manage and retreive information on existing lxc containers "
83 echo "lxc-driver.sh -c <COMMAND>_all"
84 echo "lxc-driver.sh -c <COMMAND>_lxc -l <LXCNAME>"
85 echo "<COMMAND> in {sense,start,stop,restart,destroy}"
93 while getopts "c:n:" opt ; do
103 sense_all) sense_all ;;
104 start_all) start_all ;;
105 stop_all) stop_all ;;
106 restart_all) restart_all ;;
107 destroy_all) destroy_all ;;
108 sense_lxc) sense_lxc $lxc;;
109 start_lxc) start_lxc $lxc;;
110 stop_lxc) stop_lxc $lxc;;
111 restart_lxc) restart_lxc $lxc;;
112 destroy_lxc) destroy_lxc $lxc;;