zorkian / nagios-api

A REST-like, JSON interface to Nagios
BSD 3-Clause "New" or "Revised" License
586 stars 173 forks source link

Adding init.d script #12

Closed jonlives closed 11 years ago

jonlives commented 11 years ago

Adding a basic init.d compatible startup / shutdown script

zorkian commented 11 years ago

Hey, what distro specifically is this for? It's not Ubuntu and I don't have a RHEL/CentOS/SL/whatever box nearby to test whether /etc/rc.d/init.d/functions is from that neck of the woods or what.

(Unrelated, you'd think something as straightforward as "start and stop services" would be standard across distributions. Gah.)

jonlives commented 11 years ago

Ah sorry should have clarified! That's for CentOS / Redhat

mitalhp commented 11 years ago

This init script doesnt let the api clean up the lockfile properly, if you use sigterm instead of sigkill and then use signal to capture it, it should work between server reboots:

in the init script:

kill $(cat /var/run/nagios-api.pid)

in nagios-api:

    atexit.register(_exitfunc)
    # catch sigterm and exit cleanly
    signal(SIGTERM, lambda signum, stack_frame: sys.exit(1))
zorkian commented 11 years ago

Thanks for reviewing! @jonlives you willing to update the PR and I'll get it merged in?

jonlives commented 11 years ago

@xb95 - PR updated :)

zorkian commented 11 years ago

I updated the commit message and had to add a "from signal import signal, SIGTERM" line to get it to work. It works now, and has been committed.

https://github.com/xb95/nagios-api/commit/e56bd092d281238a803977a714dcf95deea778e9

Thank you for the submission!

Finkregh commented 11 years ago

remember that this script will not work under debian: http://wiki.debian.org/LSBInitScripts This should eventually be noted somewhere... :-)