What's a simple way to get a Perl script to run as a daemon in linux?
Currently, this is on CentOS. I'd want it to start up with the system and shutdown with the system, so some /etc/rc.d/init.d
integration would also be nice, but I could always add a custom line to /etc/rc.d/rc.local
.
The easiest way is to use Proc::Daemon.
Alternately you could do all of the things Proc::Daemon does:
"/"
.Integrating with the runlevel system is easy. You need a script like the following (replace
XXXXXXXXXXXX
with the Perl script's name,YYYYYYYYYYYYYYYYYYY
with a description of what it does, and/path/to
with path to the Perl script) in/etc/init.d
. Since you are using CentOS, once you have the script in/etc/init.d
, you can just use chkconfig to turn it off or on in the various runlevels.If you don't have Proc::Daemon as suggested by Chas. Owens, here's how you'd do it by hand:
I think the easiest way is to use daemon. It allows you to run any process as a daemon. This means you don't have to worry about libraries if you, for example, decided to change to python. To use it, just use:
This should be available on most distros, but it might not be installed by default.