Opened 10 years ago
Last modified 14 months ago
#11806 new defect
Tracd --daemonize does not work without --pidfile with systemd
Reported by: | ak | Owned by: | |
---|---|---|---|
Priority: | normal | Milestone: | next-stable-1.6.x |
Component: | web frontend/tracd | Version: | 1.0.1 |
Severity: | major | Keywords: | systemd |
Cc: | Branch: | ||
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description
The following systemd config is expected to work, since systemd would try to guess the PID (see man systemd.service).
[Unit] Description=Trac Server After=network.target [Service] Type=forking ExecStart=/usr/bin/tracd -d -p 8000 -e /tmp [Install] WantedBy=multi-user.target
$ sudo systemctl status tracd ● tracd.service - Trac Server Loaded: loaded (/lib/systemd/system/tracd.service; enabled) Active: inactive (dead) since Mon 2014-11-03 00:11:32 CET; 4s ago Process: 1010 ExecStart=/usr/bin/tracd -d -p 8000 -e /tmp (code=exited, status=0/SUCCESS) Main PID: 1011 (code=exited, status=0/SUCCESS)
However, the following configuration works:
-
tracd.service
[Service] 6 6 Type=forking 7 ExecStart=/usr/bin/tracd -d -p 8000 -e /tmp 7 ExecStart=/usr/bin/tracd -d -p 8000 --pidfile=/run/tracd.pid -e /tmp 8 PIDFile=/run/tracd.pid
The status output may be a hint:
$ sudo systemctl status -l tracd ● tracd.service - Trac Server Loaded: loaded (/lib/systemd/system/tracd.service; enabled) Active: active (running) since Mon 2014-11-03 00:10:07 CET; 11s ago Process: 975 ExecStart=/usr/bin/tracd -d -p 8000 --pidfile=/run/tracd.pid -e /tmp (code=exited, status=0/SUCCESS) Main PID: 980 (tracd) CGroup: /system.slice/tracd.service └─980 /usr/bin/python /usr/bin/tracd -d -p 8000 --pidfile=/run/tracd.pid -e /tmp Nov 03 00:10:07 host systemd[1]: tracd.service: Supervising process 980 which is not our child. We'll most likely not notice when it exits.
Why does tracd exit when simply not using a pidfile?
Attachments (0)
Change History (6)
comment:1 by , 10 years ago
Keywords: | systemd added |
---|---|
Milestone: | → next-stable-1.0.x |
Owner: | set to |
Status: | new → assigned |
comment:2 by , 10 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
comment:3 by , 10 years ago
Either systemd
or tracd
removes the parent of the PID file (when both the PIDFile
directive and --pidfile
argument are specified) which makes it necessary to add a systemd
unit which creates the parent directory with higher privileges (usually /run/
or /var/run/
are owned by root
) and make the systemd
unit depend on it as a workaround.
comment:4 by , 8 years ago
Milestone: | next-stable-1.0.x → next-stable-1.2.x |
---|
Moved ticket assigned to next-stable-1.0.x since maintenance of 1.0.x is coming to a close. Please move the ticket back if it's critical to fix on 1.0.x.
comment:5 by , 5 years ago
Milestone: | next-stable-1.2.x → next-stable-1.4.x |
---|
tracd uses the "double fork" technique, so that:
waitpid()
step in our implementation…)But I'm surprised that systemd can't cope with this, as the above seems pretty common practice.
Indeed, it looks like systemd discourages the use of the double fork, so we could perhaps think about adding special support for
systemd
notification system, sd_notify. It seems pretty trivial to emulate that in Python, see e.g. pysystemd-daemon.The idea would be to use
[Service] Type=notify
, and in daemonize() we could check if there's a NOTIFY_SOCKET environment variable set. In this case, we avoid the forks altogether, unset NOTIFY_SOCKET and do a few sd_notify calls.