Correction: the *s6_service_path* parameter in the parent init.d service,
/etc/init.d/container, needs to be changed from
/run/openrc/s6-scan/${INSTANCE} to /var/svc.d/${INSTANCE}
*#!/sbin/openrc-rundescription="A supervised test service with a
logger"supervisor=s6**s6_service_path=/var/svc.d/${INSTANCE}*
*depend() {*
* need s6-svscan*
*}*
*stop_pre() {*
* docker stop ${INSTANCE}*
*}*
NB; In runlevels, dont need to include s6-svscan. Only need to include the
service to start (s6-svscan will start as a service dependency).
Further info (go from runlevel 90 > 100 > back to 90):
root@/etc/runlevels #
* ls -ld node/*lrwxrwxrwx 1 root root 24 May 25 06:17 100/container.whoami
-> /etc/init.d/container.*whoami
*lrwxrwxrwx 1 root root 11 Jan 15 04:32 100/90 -> ../90*
*root@/etc/runlevels # openrc 100container.*whoami* |/var/svc.d/*whoami
*container.*whoami* | * Starting container.*whoami* ...*
*
[ ok ]root@h003
/e/runlevels # docker ps -aCONTAINER ID IMAGE
COMMAND CREATED STATUS
PORTS NAMES68bd2ed585ed
traefik/whoami "/whoami"
25 hours ago Up 1 minute 0.0.0.0:80->80/tcp
whoamiroot@/e/runlevels # openrc 90container.*whoami*
|/var/svc.d/*whoami
*container.*whoami* |*whoami
*container.*whoami* | * Stopping container.*whoami* ...
[ ok ]*
*root@/etc/runlevels # docker ps -aCONTAINER ID IMAGE
COMMAND CREATED
STATUS PORTS NAMES68bd2ed585ed
traefik/whoami "/whoami"
25 hours ago Exited (143) 8 seconds ago
0.0.0.0:80->80/tcp whoamiroot@/etc/runlevels # *
regs,
On Thu, May 13, 2021 at 5:17 AM Damo <[email protected]> wrote:
> Hi,
>
> I've been running docker containers for a while, where I pass
> "--restart=always" into the run command, so the containers restart
> automatically after reboot. I want to have more control over the startup
> order of the containers, ie integrate into openrc start/stop and put into
> different runlevels.
>
> I've had mixed success so far. I would be interested if someone else has
> working solution. My runlevels look something like this:
>
> rl100
> container.registry
> rl90
> container.auth
> container.router
> boot
> ...
>
> FYI, i've found systemd is doing it nicely, where systemctl start/stop
> <CONTAINER> works as I would expect. I see a hardcoded dependency into the
> container PID in the unit file (podman in this case):
>
> [root@]# cat /usr/lib/systemd/system/container-libvirt-exporter.service
>
> #
>
> [Unit]
> Description=Podman container-libvirtd-exporter.service
> Documentation=man:podman-generate-systemd(1)
>
> [Service]
> Restart=always
> ExecStart=/usr/bin/podman start libvirtd-exporter
> ExecStop=/usr/bin/podman stop -t 10 libvirtd-exporter
> KillMode=none
> Type=forking
>
> PIDFile=/var/run/containers/storage/overlay-containers/9037e389e61ed01eb5dfce16fa750b6f0f01827a67640e4748e6527bbfcb6276/userdata/conmon.pid
>
> [Install]
> WantedBy=multi-user.target
>
>
> Kind regards,
> Damo
>
>