首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >/etc/inittab更新脚本从RHEL/CentOS 5.x迁移到6.x

/etc/inittab更新脚本从RHEL/CentOS 5.x迁移到6.x
EN

Server Fault用户
提问于 2011-10-05 14:46:19
回答 3查看 18.2K关注 0票数 2

在CentOS 5.7中,我有一个非分叉的perl脚本作为TCP套接字守护进程运行(此脚本是多人游戏的后端)。它正在由/etc/inittab启动和恢复:

代码语言:javascript
复制
pref:3:respawn:/bin/su -c '/usr/local/pref/pref.pl >/tmp/pref-`date +%a`.txt 2>&1' afarber

它每天晚上都在重新启动:

代码语言:javascript
复制
33    1     *     *     *     kill `cat /tmp/pref.pid`

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

自从许多卫星出现以来,这套装置对我来说一直很有效。现在,我正在尝试升级到CentOS 6.x,并在阅读“man5init”之后创建了一个新的/etc/init/pref.conf文件:

代码语言:javascript
复制
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

并且可以从

代码语言:javascript
复制
# sudo initctl start pref
pref start/running, process 2590

还可以看到在用户afarber下运行的带有"ps uawx“的脚本,并使用"netstat -an”侦听端口8080 (正如它应该的那样)。

但我的问题是,我无法停止或重新启动脚本(对于夜间的cron作业,我需要这样做):

代码语言:javascript
复制
# sudo initctl restart pref
initctl: Unknown instance:

# sudo initctl stop pref
initctl: Unknown instance:

有什么想法吗?

(我不想安装任何第三方软件,比如daemontools/Tivoli/等等--因为我想成为我的web服务器,以便很容易地重新安装和移动到其他主机上)。

更新:我看到的是-

代码语言:javascript
复制
# 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-port 8080。

在/var/log/消息中,我看到:

代码语言:javascript
复制
...
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

这可能就是我能做什么的原因吗?(也许是因为某种原因推迟了随后的产卵?)

EN

回答 3

Server Fault用户

回答已采纳

发布于 2011-10-05 15:31:06

“initctl列表”显示了什么?在创建作业之后,您是否尝试过“initctl重新加载配置”?

票数 2
EN

Server Fault用户

发布于 2012-11-19 18:35:29

问题是,在您的过程似乎要自行终止之后。我们没有pid 2083进程的日志消息,但我怀疑它在发出下一个'initctl重新启动pref‘之前意外死亡(例如,pids 2128和2133是如何死亡的)。关键是'initctl重新启动foo‘只有在foo作业名仍在运行时才能工作。如果它已经死了,您需要做一个正常的'initctl start foo‘。我也碰到这个了。我显式地调用'initctl停止foo‘,然后期望'initctl重新启动foo’就像他们处理init脚本那样工作。他们没有。你必须用'initctl start foo‘。

票数 3
EN

Server Fault用户

发布于 2011-10-05 16:20:29

偷看initctl的手册页就会发现答案。initctl命令只理解用于控制作业的开始、停止、状态谓词。没有可用的重新启动动词。

干杯!

票数 -2
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/318742

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档