0

I'm using capistrano to deploy a python service. I was trying to both start the service and also write a pidfile, so I can restart the service or stop the service later. The problem is the pidfile is always one process ID behind, and I'm not sure why. For example, if the pidfile says 123, then the actually running process is 124. Should I manually add one? Or am I writing the command wrong? I'll write the psuedo command here:

nohup python ./service.py special_argument --config /some_folder/devel.yml --log logs/service.log > /dev/null 2>&1& echo $! > /some_folder/pids/special_argument.pidfile
6
  • If it's a service, why is nohup even necessary? Commented Jun 17, 2016 at 7:02
  • Your service is probably doing a fork and exec. You're capturing the PID of the parent process that exits, but the forked child is the one that remains.
    – Karen B
    Commented Jun 17, 2016 at 7:06
  • maybe not quite a service.... it's a long running script that we are constantly making updates to. As for the fork and exec, i don't think it is, as it's just pure python. We're not using any threading. it's just a separate process. We can run the process by hand using a bash script and it works alright, but would be better if we can launch with capistrano.
    – Allen
    Commented Jun 17, 2016 at 7:10
  • You may also be capturing the PID of the shell capistrano spawns to run its tasks. Without knowing how you're capturing the PID (code?), the rest is guesswork.
    – Karen B
    Commented Jun 17, 2016 at 8:35
  • Also, just to confirm, you've opened the python script and made sure it's not calling fork, correct? Python scripts can do that.
    – Karen B
    Commented Jun 17, 2016 at 8:36

1 Answer 1

0

Got around this by delegating the python script to write it's own pidfile.

You must log in to answer this question.

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