容器内reboot/shutdown

功能描述

系统容器支持在容器内执行reboot和shutdown命令。执行reboot命令效果同重启容器一致;执行shutdown命令效果同停止容器一致。

参数说明

命令

参数

参数指定值说明

isula create/run

—restart

  • 字符串变量。
  • 可取指定值:

    on-reboot:表示重启系统容器。

      

约束限制

  • shutdown功能,依赖于不同的OS,以实际容器运行环境对应OS为准。
  • 执行“shutdown -h now”命令关闭系统时,不能多次占用console。例如“isula run -ti”命令打开一个console,在另一个host bash中isula attach该容器,会打开另一个console,此时执行shutdown会失败。

使用示例

  • 容器启动时指定--restart on-reboot参数,示例如下:

    1. [root@localhost ~]# isula run -tid --restart on-reboot --system-container --external-rootfs /root/myrootfs none init
    2. 106faae22a926e22c828a0f2b63cf5c46e5d5986ea8a5b26de81390d0ed9714f
  • 进入容器执行reboot命令:

    1. [root@localhost ~]# isula exec -it 10 bash
    2. [root@localhost /]# reboot

    查看容器是否重启:

    1. [root@localhost ~]# isula exec -it 10 ps aux
    2. USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
    3. root 1 0.1 0.0 21588 9504 ? Ss 12:11 0:00 init
    4. root 14 0.1 0.0 27024 9376 ? Ss 12:11 0:00 /usr/lib/system
    5. root 17 0.0 0.0 18700 5876 ? Ss 12:11 0:00 /usr/lib/system
    6. dbus 22 0.0 0.0 9048 3624 ? Ss 12:11 0:00 /usr/bin/dbus-d
    7. root 26 0.0 0.0 8092 3012 ? Rs+ 12:13 0:00 ps aux
  • 进入容器执行shutdown命令:

    1. [root@localhost ~]# isula exec -it 10 bash
    2. [root@localhost /]# shutdown -h now
    3. [root@localhost /]# [root@localhost ~]#

    检查容器是否停止:

    1. [root@localhost ~]# isula exec -it 10 bash
    2. Error response from daemon: Exec container error;Container is not running:106faae22a926e22c828a0f2b63cf5c46e5d5986ea8a5b26de81390d0ed9714f