Changes between Version 1 and Version 2 of TipAndDoc/Linux/LXC/ArchLinux


Ignore:
Timestamp:
Apr 23, 2016 5:23:30 PM (8 years ago)
Author:
mitty
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TipAndDoc/Linux/LXC/ArchLinux

    v1 v2  
    77 > I’m on a laptop with wireless, so I can’t just create a bridge and give IPs to containers from an upstream DHCP server. I needed to do NAT and essentially simulate/replicate how docker networking works. 
    88 
    9  = DHCP = 
     9 = lxc.service = 
     10 == A stop job is running == 
     11 * lxc.serviceを有効にしないと、ホストOSシャットダウン時にコンテナが自動シャットダウンされず90秒タイムアウト待ちが発生する 
     12  * [[Image(lxc-A_stop_job_is_running.png,33%)]] 
     13 
     14 * mitty@lxc-host:~$ journalctl 
     15{{{ 
     16Apr 17 22:52:41 lxc-host sudo[1908]:    mitty : TTY=pts/0 ; PWD=/home/mitty ; USER=root ; COMMAND=/usr/bin/sh -c poweroff 
     17 
     18(snip) 
     19 
     20Apr 17 22:52:41 lxc-host systemd[529]: Received SIGRTMIN+24 from PID 1913 (kill). 
     21Apr 17 22:52:41 lxc-host systemd[1]: Stopped User Manager for UID 1000. 
     22Apr 17 22:52:42 lxc-host systemd[1]: Started Generate shutdown-ramfs. 
     23Apr 17 22:54:11 lxc-host systemd[1]: session-c1.scope: Stopping timed out. Killing. 
     24Apr 17 22:54:11 lxc-host systemd[1]: Stopped Session c1 of user mitty. 
     25}}} 
     26mitty@test:~$ journalctl 
     27{{{ 
     28Apr 17 22:52:41 test systemd[1]: Received SIGHUP. 
     29Apr 17 22:52:41 test systemd[1]: Received SIGTERM. 
     30Apr 17 22:52:41 test systemd[1]: Reexecuting. 
     31Apr 17 22:52:41 test systemd[1]: systemd 229 running in system mode. (+PAM -AUDIT -SELINUX -IMA -APPARMOR +SMACK -SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN) 
     32Apr 17 22:52:41 test systemd[1]: Detected virtualization lxc. 
     33Apr 17 22:52:41 test systemd[1]: Detected architecture x86-64. 
     34Apr 17 22:52:41 test systemd[1]: Failed to install release agent, ignoring: No such file or directory 
     35}}} 
     36 
     37 === コンテナのシャットダウンについて === 
     38 * man systemd 
     39{{{ 
     40SIGNALS 
     41       SIGTERM 
     42           Upon receiving this signal the systemd system manager serializes 
     43           its state, reexecutes itself and deserializes the saved state 
     44           again. This is mostly equivalent to systemctl daemon-reexec. 
     45 
     46           systemd user managers will start the exit.target unit when this 
     47           signal is received. This is mostly equivalent to systemctl --user 
     48           start exit.target. 
     49 
     50(snip) 
     51 
     52       SIGHUP 
     53           Reloads the complete daemon configuration. This is mostly 
     54           equivalent to systemctl daemon-reload. 
     55 
     56(snip) 
     57 
     58       SIGRTMIN+4 
     59           Powers off the machine, starts the poweroff.target unit. This is 
     60           mostly equivalent to systemctl start poweroff.target. 
     61 
     62(snip) 
     63 
     64       SIGRTMIN+14 
     65           Immediately powers off the machine. 
     66}}} 
     67 
     68 * /usr/share/lxc/config/archlinux.common.conf 
     69{{{ 
     70# Set the halt/stop signals 
     71lxc.haltsignal=SIGRTMIN+4 
     72lxc.stopsignal=SIGRTMIN+14 
     73}}} 
     74 * [https://lists.linuxcontainers.org/pipermail/lxc-devel/2012-May/002468.html (lxc-devel) Shutting down containers properly] 
     75 * [https://bbs.archlinux.org/viewtopic.php?id=181032 (Solved) LXC shutdown of archlinux containers not working (lxc-stop) / System Administration / Arch Linux Forums] 
     76 
     77 * lxc-stop 
     78  * Host 
     79{{{ 
     80Apr 19 22:15:54 lxc-host sudo[589]:    mitty : TTY=pts/0 ; PWD=/home/mitty ; USER=root ; COMMAND=/usr/bin/lxc-stop -n test 
     81}}} 
     82  * container 
     83{{{ 
     84Apr 19 22:15:54 test systemd[1]: Received SIGRTMIN+4. 
     85Apr 19 22:15:54 test systemd[1]: Stopping User Manager for UID 1000... 
     86Apr 19 22:15:54 test systemd[1]: Stopped target Multi-User System. 
     87}}} 
     88 
     89 == systemctl enable lxc.service == 
     90 * /usr/lib/systemd/system/lxc.service 
     91{{{ 
     92ExecStart=/usr/lib/lxc/lxc-containers start 
     93ExecStop=/usr/lib/lxc/lxc-containers stop 
     94}}} 
     95 * /usr/lib/lxc/lxc-containers 
     96{{{ 
     97# STOPOPTS are stop options.  The can be used for anything else to stop. 
     98#       If you want to kill containers fast, use -k 
     99STOPOPTS="-a -A -s" 
     100 
     101(snip) 
     102 
     103case "$1" in 
     104 
     105(snip) 
     106 
     107    stop) 
     108 
     109(snip) 
     110 
     111        "$bindir"/lxc-autostart $STOPOPTS $SHUTDOWNDELAY 
     112}}} 
     113 * man lxc-autostart 
     114{{{ 
     115       -s,--shutdown 
     116              Request  a  clean  shutdown. If a [-t timeout] greater than 0 is 
     117              given and the container has not shut down within this period, it 
     118              will be killed as with the [-k kill] option. 
     119 
     120(snip) 
     121 
     122       -a,--all 
     123              Ignore lxc.group and select all auto-started containers. 
     124 
     125       -A,--ignore-auto 
     126              Ignore  the  lxc.start.auto  flag. Combined with -a, will select 
     127              all containers on the system. 
     128}}} 
     129 
     130 * mitty@lxc-host:~$ sudo systemctl enable --now lxc.service 
     131{{{ 
     132Created symlink from /etc/systemd/system/multi-user.target.wants/lxc.service to /usr/lib/systemd/system/lxc.service. 
     133}}} 
     134 * mitty@lxc-host:~$ journalctl 
     135{{{ 
     136Apr 19 23:22:34 lxc-host sudo[573]:    mitty : TTY=pts/0 ; PWD=/home/mitty ; USER=root ; COMMAND=/usr/bin/sh -c poweroff 
     137 
     138(snip) 
     139 
     140Apr 19 23:22:34 lxc-host systemd[1]: Stopped LXC Container Initialization and Autoboot Code. 
     141}}} 
     142 * mitty@test:~$ journalctl 
     143{{{ 
     144Apr 19 23:22:34 test systemd[1]: Received SIGTERM. 
     145Apr 19 23:22:34 test systemd[1]: Reexecuting. 
     146Apr 19 23:22:34 test systemd[1]: systemd 229 running in system mode. (+PAM -AUDIT -SELINUX -IMA -APPARMOR +SMACK -SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN) 
     147Apr 19 23:22:34 test systemd[1]: Detected virtualization lxc. 
     148Apr 19 23:22:34 test systemd[1]: Detected architecture x86-64. 
     149Apr 19 23:22:34 test systemd[1]: Failed to install release agent, ignoring: No such file or directory 
     150Apr 19 23:22:34 test systemd[1]: Received SIGHUP. 
     151Apr 19 23:22:34 test systemd[1]: Received SIGRTMIN+4. 
     152Apr 19 23:22:34 test systemd[1]: Reloading. 
     153Apr 19 23:22:34 test systemd[1]: Stopped target Multi-User System. 
     154 
     155(snip) 
     156 
     157Apr 19 23:22:34 test systemd[1]: Shutting down. 
     158Apr 19 23:22:34 test systemd-journald[13]: Journal stopped 
     159}}} 
     160 
     161 = dhcpcd.service = 
    10162 
    11163 == no valid interfaces found ==