[Lxc-users] shutting down CentOS6 container

Papp Tamas tompos at martos.bme.hu
Mon Oct 17 20:12:18 UTC 2011


On 10/17/2011 10:02 PM, Milos Negovanovic wrote:
> On Mon, Oct 17, 2011 at 10:36:24PM +0300, Iliyan ilf Stoyanov wrote:
>> Hi Milos,
>>
>> have you tried doing lxc-console --name $NAME_OF_YOUR_CENTOS6_CONTAINER,
>> then loging in and issuing shutdown -h now. It works for me on Fedora
>> 15/SL6.1.
>>
>> BR,
>> --ilf
> I am looking for a way to automatically shutdown container. Something I
> can use from my rc scripts on the host to orderly shutdown containers on
> host OS reboot/shutdown. I know I can ssh into the container and issue
> shutdown command, that works, but thats not what I am looking for.
>

kill -INT init

I use this diff on ubuntu host:

--- lxc.orig    2011-10-16 22:59:24.186322805 +0200
+++ lxc    2011-10-17 22:10:17.974920307 +0200
@@ -52,6 +52,37 @@
    fi
  }

+stop_one() {
+    name=$1
+#    dir_cgroup=`grep -w cgroup /proc/mounts|awk '{ print $2 }'`
+#    if [ ! -d $dir_cgroup/$name ]; then
+#        log_failure_msg "$name is not running."
+#        return
+#    fi
+    if ! is_running $name;then
+        log_failure_msg "$name is not running."
+    fi
+
+    echo -n "Stopping $name"
+    pid_init=`lxc-ps --name $name | grep init$ | awk '{ print $2 }'`
+
+    kill -INT $pid_init
+    count=0
+    while lxc-ps --name $name | egrep -qv '(init$|CONTAINER    PID 
TTY          TIME CMD)';do
+        if [ $count -ge 600 ];then
+            log_failure_msg "Container $name cannot be stopped on the 
proper way."
+            return
+        fi
+        echo -n '.';
+        sleep 1;
+        count=$(($count+1))
+    done
+
+    lxc-stop -n $name
+    echo " done."
+    log_success_msg "Container $name has been stopped successfully."
+}
+
  action_all() {
    action=$1
    nolog=$2
@@ -80,7 +111,8 @@
      ;;
    stop)
      log_daemon_msg "Stopping $DESC"
-    action_all "lxc-stop -n"
+    #action_all "lxc-stop -n"
+    action_all stop_one
      ;;
    restart|force-reload)
      log_daemon_msg "Restarting $DESC"


tamas




More information about the lxc-users mailing list