简体   繁体   English

在启动Linux时守护Perl脚本

[英]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. 我有CENTOS的自定义版本,需要始终将perl脚本作为守护程序运行。

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. 因此,我有一个rc1脚本,其中包含许多在计算机启动时运行的命令,其中的最后一行是我尝试守护该脚本的位置。 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. rc1脚本中的其他所有内容都运行良好,并且该脚本不会输出任何错误,但是,当我检查启动程序是否正在运行时,该守护程序没有运行。

Is there another way that I can get the script to run on startup? 有没有其他方法可以让脚本在启动时运行? Or any ideas on why this method doesn't work? 或对这种方法为何行不通的任何想法?

Proc::Daemon offers what you're looking for. Proc :: Daemon提供您想要的东西。

See this previously asked question: How can I run a Perl script as a system daemon in linux? 看到这个先前的问题: 如何在Linux中将Perl脚本作为系统守护程序运行?

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. 问题是@INC到我的脚本被调用时还没有完全加载所有模块,因此守护程序没有运行。 I used the PERL5LIB command to add the appropriate directories. 我使用PERL5LIB命令添加适当的目录。

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

where /perl ; 其中/perl ; /custom/lib and /usr/local/lib64/perl5 are the directories which were missing from @INC /custom/lib/usr/local/lib64/perl5是@INC缺少的目录

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM