9

I used the following config to start beanstalkd process

[Service]
ExecStart=/usr/local/bin/beanstalkd 
ExecStartPost=pgrep beanstalkd > /var/run/beanstalkd.pid

The last line is supposed to generate a pidfile after the process in launched, but the file is not created. why ?

Or is there another way to force pidfile creation in systemd ?

3 Answers 3

11

systemd does not require a pidfile for a Type=simple service. It will manage the daemon in the foreground. systemctl status SERVICE_NAME will show the pid of the main process (and of any other processes in the cgroup).

For completeness, your ExecStartPost line did not work because systemd does not use a shell to execute commands and does not perform $PATH lookup, so you would have to use ExecStartPost=/bin/sh -c "...", but as I said, the line is unnecessary.

1
  • 2
    Thank you it works. I know systemd doesn't need a pidfile, but i'd like to generate one to monitor process with monit
    – jney
    Mar 3, 2013 at 10:30
3

In case you still need an answer on this (or someone else does), you need a shell context to run pgrep, so the correct command would be

ExecStartPost=/usr/bin/zsh -c 'pgrep process_name > /var/run/process_name.pid'
1
  • 4
    I recommend using "sh" since it can do everything required and is more commonly available ExecStartPost=/bin/sh -c 'pgrep process_name > /var/run/process_name.pid' Oct 1, 2016 at 20:37
0

This shows the order of execs is from BOTTOM to TOP http://lists.fedoraproject.org/pipermail/devel/2011-July/153897.html Your ExecStartPost is running before ExecStart

1
  • 2
    The post you link points out that the ordering is inverted in the status output, not that it's actually temporally inverse. ExecStartPre happens before ExecStart, and ExecStartPost happens after. May 1, 2016 at 0:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .