在启动Linux时使用perl脚本

时间:2022-12-06 13:24:22

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. 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脚本,它有很多命令在机器启动时运行,在它的最后一行是我试图使脚本daemean。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?

是否有另一种方法可以让脚本在启动时运行?或者对为什么这个方法不起作用有什么看法?

2 个解决方案

#1


2  

Proc::Daemon offers what you're looking for.

守护进程提供您正在寻找的内容。

See this previously asked question: How can I run a Perl script as a system daemon in linux?

请参见前面提出的问题:如何在linux中作为系统守护程序运行Perl脚本?

#2


1  

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.

问题是,当我的脚本被调用时,@INC并没有完全加载所有的模块,所以我的守护进程没有运行。我使用PERL5LIB命令添加适当的目录。

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

在那里/ perl;/custom/lib和/usr/local/lib64/perl5是@INC所缺少的目录。

#1


2  

Proc::Daemon offers what you're looking for.

守护进程提供您正在寻找的内容。

See this previously asked question: How can I run a Perl script as a system daemon in linux?

请参见前面提出的问题:如何在linux中作为系统守护程序运行Perl脚本?

#2


1  

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.

问题是,当我的脚本被调用时,@INC并没有完全加载所有的模块,所以我的守护进程没有运行。我使用PERL5LIB命令添加适当的目录。

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

在那里/ perl;/custom/lib和/usr/local/lib64/perl5是@INC所缺少的目录。