1

After startup of system my script starts from crontab as daemon. It works for a while and suspends/hangs without response. After that I cannot run it like sudo python script.py restart, because it says: File "/usr/lib/pymodules/python2.7/daemon/runner.py", line 149, in _stop "PID file %(pidfile_path)r not locked" % vars()) daemon.runner.DaemonRunnerStopFailureError: PID file '/home/pi/testdaemon.pid' not locked

In init from script there is:

def __init__(self):
  self.stdin_path = '/dev/null'
  self.stdout_path = '/dev/null'
  self.stderr_path = '/dev/null'
  self.pidfile_path = '/home/pi/testdaemon.pid'
  self.pidfile_timeout = 5

Any idea of solving this problem would be great!

EDIT:

It seems that I have found my problem. I couldn't restart daemon when it stopped because whole mechanism wanted to stop my daemon at first place and it couldn't because it was already stopped. Then I found out that there was an issue inside my script which made whole run only for a few seconds and crash. Anyway, thank you for every answers!

mefe
  • 307
  • 1
  • 6
  • 14
  • You might take a look at [pandaemonium](https://pypi.python.org/pypi/pandaemonium) for the daemon portion -- it has pretty good debugging support. Full disclosure: I'm the author of `pandaemonium`. – Ethan Furman Mar 09 '15 at 02:12

1 Answers1

1

I cannot tell why your script hangs -- but apparently its process is still around so the clean-up never happens. You can force the clean-up by examining /home/pi/testdaemon.pid, verifying that the process id it contains is indeed still running, killing that process (with a -9 if need be), and, just for completeness, removing /home/pi/testdaemon.pid.

After that, you should be able to re-run your script. However, the core problem is, why does your script "hang without response" -- and you're just not giving us any info to help you debug that problem (perhaps a separate question is more appropriate for that)... these are just "emergency steps" you can take to let you run your script again, but of course they do nothing to assess or fix the root cause of your problem!

Alex Martelli
  • 854,459
  • 170
  • 1,222
  • 1,395
  • Unfortunately, my script not hangs, but stops. While it's running I can see `testdaemon.pid` and `testdaemon.pid.lock`, but after short time it stops and these files are no longer available. So from one side - it starts at startup and somehow crashes and from the other side I cannot start/restart it after crash because of error I pasted in first post. I hope that after managing this error, I can manage with script crashing. Or ask another question as you suggested. – mefe Mar 09 '15 at 09:11