8

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 ?

jney
  • 233
  • 1
  • 2
  • 8

3 Answers3

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.

Chris Williams
  • 231
  • 2
  • 2
  • 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 03 '13 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'
Charles Duffy
  • 946
  • 2
  • 10
  • 19
Tomaž Zaman
  • 131
  • 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'` – Benjamin Peter Oct 01 '16 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

James
  • 17
  • 2
  • 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. – Charles Duffy May 01 '16 at 00:20