1 |
Correction: the *s6_service_path* parameter in the parent init.d service, |
2 |
/etc/init.d/container, needs to be changed from |
3 |
/run/openrc/s6-scan/${INSTANCE} to /var/svc.d/${INSTANCE} |
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
*#!/sbin/openrc-rundescription="A supervised test service with a |
10 |
logger"supervisor=s6**s6_service_path=/var/svc.d/${INSTANCE}* |
11 |
|
12 |
*depend() {* |
13 |
* need s6-svscan* |
14 |
*}* |
15 |
|
16 |
*stop_pre() {* |
17 |
* docker stop ${INSTANCE}* |
18 |
*}* |
19 |
|
20 |
NB; In runlevels, dont need to include s6-svscan. Only need to include the |
21 |
service to start (s6-svscan will start as a service dependency). |
22 |
|
23 |
Further info (go from runlevel 90 > 100 > back to 90): |
24 |
|
25 |
root@/etc/runlevels # |
26 |
* ls -ld node/*lrwxrwxrwx 1 root root 24 May 25 06:17 100/container.whoami |
27 |
-> /etc/init.d/container.*whoami |
28 |
*lrwxrwxrwx 1 root root 11 Jan 15 04:32 100/90 -> ../90* |
29 |
|
30 |
|
31 |
*root@/etc/runlevels # openrc 100container.*whoami* |/var/svc.d/*whoami |
32 |
*container.*whoami* | * Starting container.*whoami* ...* |
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
* |
40 |
[ ok ]root@h003 |
41 |
/e/runlevels # docker ps -aCONTAINER ID IMAGE |
42 |
COMMAND CREATED STATUS |
43 |
PORTS NAMES68bd2ed585ed |
44 |
traefik/whoami "/whoami" |
45 |
25 hours ago Up 1 minute 0.0.0.0:80->80/tcp |
46 |
whoamiroot@/e/runlevels # openrc 90container.*whoami* |
47 |
|/var/svc.d/*whoami |
48 |
*container.*whoami* |*whoami |
49 |
*container.*whoami* | * Stopping container.*whoami* ... |
50 |
|
51 |
[ ok ]* |
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
*root@/etc/runlevels # docker ps -aCONTAINER ID IMAGE |
58 |
COMMAND CREATED |
59 |
STATUS PORTS NAMES68bd2ed585ed |
60 |
traefik/whoami "/whoami" |
61 |
25 hours ago Exited (143) 8 seconds ago |
62 |
0.0.0.0:80->80/tcp whoamiroot@/etc/runlevels # * |
63 |
|
64 |
|
65 |
regs, |
66 |
|
67 |
On Thu, May 13, 2021 at 5:17 AM Damo <dhatchett2@×××××.com> wrote: |
68 |
|
69 |
> Hi, |
70 |
> |
71 |
> I've been running docker containers for a while, where I pass |
72 |
> "--restart=always" into the run command, so the containers restart |
73 |
> automatically after reboot. I want to have more control over the startup |
74 |
> order of the containers, ie integrate into openrc start/stop and put into |
75 |
> different runlevels. |
76 |
> |
77 |
> I've had mixed success so far. I would be interested if someone else has |
78 |
> working solution. My runlevels look something like this: |
79 |
> |
80 |
> rl100 |
81 |
> container.registry |
82 |
> rl90 |
83 |
> container.auth |
84 |
> container.router |
85 |
> boot |
86 |
> ... |
87 |
> |
88 |
> FYI, i've found systemd is doing it nicely, where systemctl start/stop |
89 |
> <CONTAINER> works as I would expect. I see a hardcoded dependency into the |
90 |
> container PID in the unit file (podman in this case): |
91 |
> |
92 |
> [root@]# cat /usr/lib/systemd/system/container-libvirt-exporter.service |
93 |
> |
94 |
> # |
95 |
> |
96 |
> [Unit] |
97 |
> Description=Podman container-libvirtd-exporter.service |
98 |
> Documentation=man:podman-generate-systemd(1) |
99 |
> |
100 |
> [Service] |
101 |
> Restart=always |
102 |
> ExecStart=/usr/bin/podman start libvirtd-exporter |
103 |
> ExecStop=/usr/bin/podman stop -t 10 libvirtd-exporter |
104 |
> KillMode=none |
105 |
> Type=forking |
106 |
> |
107 |
> PIDFile=/var/run/containers/storage/overlay-containers/9037e389e61ed01eb5dfce16fa750b6f0f01827a67640e4748e6527bbfcb6276/userdata/conmon.pid |
108 |
> |
109 |
> [Install] |
110 |
> WantedBy=multi-user.target |
111 |
> |
112 |
> |
113 |
> Kind regards, |
114 |
> Damo |
115 |
> |
116 |
> |