lxc auto start on boot

最後更新: 2020-07-20

目錄

 


Auto Start

 

"lxc-autostart" processes containers with lxc.start.auto & -g "onboot,"

Contrainer Setting

  • lxc.start.auto
  • lxc.start.order
  • lxc.start.delay
  • lxc.group (要小心設定)

# Whether the container should be auto-started

i.e. The auto-starting a series of containers at once.

lxc.start.auto = 1

i.e. The startup will be in order of 2 (沒有設定 order 的會在 group 內最後 start)

lxc.start.order = 2

# 延遲多久才啟動下一個 vps => give the current container time to begin initialization (# Unit: seconds)

lxc.start.delay = 30

# Two groups are special: "onboot" group, "NULL" group (Default 只有此兩個 Group)

# 設定此 vps 是屬於 web Group
# 由於 BOOTGROUPS 只有 "onboot,", 所以它是不會 auto-start
lxc.group = web

BOOTGROUPS

/etc/init/lxc.conf 的 code

# These can be overridden in /etc/default/lxc
...
[ "x$LXC_AUTO" = "xtrue" ] || exit 0

if [ -n "$BOOTGROUPS" ]
then
        BOOTGROUPS="-g $BOOTGROUPS"
fi
...

/etc/default/lxc

# start containers at boot
LXC_AUTO="true"

# Leading comma, trailing comma => NULL group
BOOTGROUPS="onboot,"

Remark: MySetting

LXC_AUTO="true"
BOOTGROUPS="onboot,,web"

Checking

lxc-ls -f

NAME  STATE   AUTOSTART GROUPS IPV4           IPV6
lamp  RUNNING 1         web    192.168.123.11 -
proxy RUNNING 1         web    192.168.123.14 -
sshgw RUNNING 1         -      192.168.123.13 -
tools RUNNING 1         web    192.168.123.15 -

OS Setting

# C8