Docker Community Forums

Share and learn in the Docker community.

Systemd for docker service to start at boot

docker

(Eekfonky) #1

Using Docker docker-hypriot_1.11.1-1_armhf.deb on a Raspberry Pi3 running OSMC. I have set a systemd service in /etc/systemd/system and have followed the instructions as per https://docs.docker.com/engine/admin/host_integration/

Here is the systemd file;
[Unit]
Description=NZBGet container
Requires=docker.service
After=docker.service

[Service]
Restart=always
ExecStart=/usr/bin/docker run -d -p 6789:6789 --name=nzbget --restart=always -e PUID=1000 -e PGID=1000 -e /etc/localtime:/etc/localtime:gb -v /opt/nzbget:/config -v /mnt:/Downloads lsioarmhf/nzbget
ExecStop=/usr/bin/docker stop -t 2 nzbget
ExecStopPost=/usr/bin/docker rm -f nzbget

[Install]
WantedBy=default.target

When checking it with sudo systemctl status I get this;
* nzbget.service - NZBGet container
Loaded: loaded (/etc/systemd/system/nzbget.service; enabled)
Active: deactivating (stop) since Sun 2016-11-27 16:21:09 GMT; 2s ago
Process: 4222 ExecStopPost=/usr/bin/docker rm -f nzbget (code=exited, status=0/SUCCESS)
Process: 4257 ExecStart=/usr/bin/docker run -d -p 6789:6789 --name=nzbget --restart=always -e PUID=1000 -e PGID=1000 -e /etc/localtime:/etc/localtime:gb -v /opt/nzbget:/config -v /mnt:/Downloads lsioarmhf/nzbget (code=exited, status=0/SUCCESS)
Main PID: 4257 (code=exited, status=0/SUCCESS); : 4357 (docker)
CGroup: /system.slice/nzbget.service
-control-4357 /usr/bin/docker stop -t 2 nzbget

Nov 27 16:21:06 osmc systemd[1]: Started NZBGet container.
Nov 27 16:21:08 osmc docker[4257]: e989fcbcea99227d4de745df7d41cb300eedf60ed2dcb81c623557f5894acb5b

Where am I going wrong?


(David Maze) #2

[quote=“eekfonky, post:1, topic:25360, full:true”]
ExecStart=/usr/bin/docker run -d -p 6789:6789 --name=nzbget --restart=always -e PUID=1000 -e PGID=1000 -e /etc/localtime:/etc/localtime:gb -v /opt/nzbget:/config -v /mnt:/Downloads lsioarmhf/nzbget
[…]
Main PID: 4257 (code=exited, status=0/SUCCESS); : 4357 (docker)

[quote]

docker run -d always exits immediately. (Also, I think the /etc/localtime probably needs to have a -v before it, not a -v.) IIRC systemd tries to keep its ExecStart process running forever under the assumption that it’s a long-running daemon, and the best thing to do in this case (assuming you’re stuck with systemd on the host) is to just remove the -d option.


(Eekfonky) #3
[Unit]
Description=NZBGet container
Requires=docker.service
After=docker.service

[Service]
ExecStart=/usr/bin/docker run -p 6789:6789 --name=nzbget --restart=always -e PUID=1000 -e PGID=1000 -e /etc/localtime:/etc/localtime:gb -v /opt/nzbget:/config -v /mnt:/Downloads lsioarmhf/nzbget
ExecStop=/usr/bin/docker stop -t 2 nzbget
ExecStopPost=/usr/bin/docker rm -f nzbget

[Install]
WantedBy=default.target

This did the trick