/ etc / inittab respawn脚本从RHEL / CentOS 5.x迁移到6.x

我在CentOS 5.7中有一个非分叉的perl脚本作为TCP-sockets守护进程运行(这个脚本是多人游戏的后端)。 它正在被/ etc / inittab启动和重新生成:

pref:3:respawn:/bin/su -c '/usr/local/pref/pref.pl >/tmp/pref-`date +%a`.txt 2>&1' afarber 

它正在每天晚上由cronjob重新启动:

 33 1 * * * kill `cat /tmp/pref.pid` 

(其中/tmp/pref.pid文件是由脚本本身创build的)。

这个设置对我来说很好,因为很多卫星。 现在我正在尝试升级到CentOS 6.x,并在阅读“man 5 init”之后创build了一个新的/etc/init/pref.conf文件:

 start on stopped rc RUNLEVEL=3 stop on starting rc RUNLEVEL=[!3] console output respawn chdir /tmp exec /bin/su -c '/usr/local/pref/pref.pl >/tmp/pref-`date +%a`.txt 2>&1' afarber 

并可以启动它

 # sudo initctl start pref pref start/running, process 2590 

还可以看到用户在“ps uawx”下面运行的脚本,并在“端口8080”(应该是)用“netstat -an”监听。

但我的问题是,我不能停止或重新启动脚本(我需要每晚cronjob):

 # sudo initctl restart pref initctl: Unknown instance: # sudo initctl stop pref initctl: Unknown instance: 

有什么想法吗?

(我不想安装任何第三方软件,如daemontools / Tivoli /等 – 因为我想成为我的networking服务器,可以轻松地重新安装和移动到其他主机)。

更新:这是我所看到的 –

 # initctl reload-configuration # initctl list rc stop/waiting tty (/dev/tty3) start/running, process 1515 tty (/dev/tty2) start/running, process 1513 tty (/dev/tty1) start/running, process 1511 tty (/dev/tty6) start/running, process 1521 tty (/dev/tty5) start/running, process 1519 tty (/dev/tty4) start/running, process 1517 plymouth-shutdown stop/waiting control-alt-delete stop/waiting kexec-disable stop/waiting quit-plymouth stop/waiting rcS stop/waiting prefdm stop/waiting pref start/running, process 1507 init-system-dbus stop/waiting splash-manager stop/waiting start-ttys stop/waiting rcS-sulogin stop/waiting serial stop/waiting # initctl status pref pref start/running, process 1507 # initctl restart pref pref start/running, process 2083 # initctl restart pref initctl: Unknown instance: # initctl restart pref initctl: Unknown instance: 

UPDATE2:

我的脚本有两个层次:

1)当它得到SIGTERM或SIGINT时,它将一些数据写入PostgreSQL,这需要10-15秒

2)多次启动时,后续运行将立即失败,因为只有第一个实例将能够侦听TCP端口8080

在/ var / log / messages中我看到:

 ... 17:44:25 static init: pref main process ended, respawning 17:44:26 static init: pref main process (2128) terminated with status 98 17:44:26 static init: pref main process ended, respawning 17:44:26 static init: pref main process (2133) terminated with status 98 17:44:26 static init: pref respawning too fast, stopped 

这一切都是原因,有什么我可以做的吗? (也许以某种方式延迟后续的产卵?)

什么是'initctl列表'显示? 创build作业后,您是否尝试过“initctl reload-configuration”?

问题是,你的过程似乎是由自己终止。 我们没有使用pid 2083进程的日志消息,但是我怀疑在发出下一个“initctl restart pref”(比如2128和2133如何死亡)之前它意外死亡。 关键是如果foo作业名仍在运行,那么'initctl restart foo'只会生效。 如果死了,你需要做一个正常的'initctl start foo'。 我也遇到了这个。 我明确地调用了'initctl stop foo',然后期待'initctl restart foo'就像使用init脚本一样工作。 他们没有。 你必须使用'initctl start foo'。

在initctl的手册页上偷看会显示答案。 initctl命令只能识别控制作业的启动,停止和状态动词。 没有可用的重启动词。

干杯!