Edgewall Software
Modify

Opened 9 years ago

Last modified 7 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]  
    66Type=forking
    7 ExecStart=/usr/bin/tracd -d -p 8000 -e /tmp
     7ExecStart=/usr/bin/tracd -d -p 8000 --pidfile=/run/tracd.pid -e /tmp
     8PIDFile=/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 Christian Boos, 9 years ago

Keywords: systemd added
Milestone: next-stable-1.0.x
Owner: set to Christian Boos
Status: newassigned

tracd uses the "double fork" technique, so that:

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.

comment:2 by Ryan J Ollos, 9 years ago

Owner: Christian Boos removed
Status: assignednew

comment:3 by krichter@…, 9 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 Ryan J Ollos, 7 years ago

Milestone: next-stable-1.0.xnext-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 Ryan J Ollos, 4 years ago

Milestone: next-stable-1.2.xnext-stable-1.4.x

comment:6 by Ryan J Ollos, 7 months ago

Milestone: next-stable-1.4.xnext-stable-1.6.x

Milestone renamed

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The ticket will remain with no owner.
The ticket will be disowned.
as The resolution will be set. Next status will be 'closed'.
The owner will be changed from (none) to anonymous. Next status will be 'assigned'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.