Skip to content

Instantly share code, notes, and snippets.

@berekuk
Created May 24, 2012 22:25
Show Gist options
  • Select an option

  • Save berekuk/2784554 to your computer and use it in GitHub Desktop.

Select an option

Save berekuk/2784554 to your computer and use it in GitHub Desktop.
daemon-control-issues
Sorry, I'm too lazy to file each one of these bugs separately, and I really think you should adopt `Ubic::Daemon` instead.
You should close all filehandles; simple test: `ssh localhost '/etc/init.d/foo start'` will hang otherwise.
`exit 1` if service is already running is not LSB compatible. Also, not supporting force-reload and try-restart.
Not saving pidfile atomically means that your code will break if you recreated the pidfile but failed because of random kill (oom, for example), or after reboot. Simple test: `echo >file.pid` will break your service forever.
If you don't keep any additional guid in your pidfile, this means that at the time you call `/etc/init.d/foo stop`, you can kill the wrong process.
I didn't test this, but I think fork(1) is broken; you're storing the pidfile, but what's the point, if the self-daemonizing code will double-fork and change its pid?
This one is really important: you should take locks when starting and stopping; otherwise, you will see tons of random race-conditions.
Not really bugs but missing features:
* TERM TERM INT KILL? really??
* guaranteed `sleep 1` on the simplest stop is annoying; I know it's unavoidable, but Ubic::Daemon does sleep(0.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment