Skip to content
Advertisement

Daemonize a perl script at startup Linux

I have a custom version of CENTOS that I need to run a perl script as a daemon in at all times.

To do this I want to get it to run on startup as a daemon.

When the machine is on I can daemonize the script with the command

daemonize /var/myfolder/myscript.pl

And this works fine.

So I have an rc1 script which has a number of commands that run when the machine starts, and the very last line in it is where I try to daemonize that script. Everything else in the rc1 script runs fine, and the script doesn’t output any errors, however when I check to see if the daemon is running on start up, it isn’t running.

Is there another way that I can get the script to run on startup? Or any ideas on why this method doesn’t work?

Advertisement

Answer

The problem was that @INC hadn’t fully loaded all of the modules by the time my script was called, and so my daemon wasn’t running. I used the PERL5LIB command to add the appropriate directories.

PERL5LIB='/perl:/custom/lib:/usr/local/lib64/perl5' /var/myfolder/myscript.pl &

where /perl; /custom/lib and /usr/local/lib64/perl5 are the directories which were missing from @INC

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement