我有一个自定义的初始化脚本,并且我希望在进程终止时重新生成该脚本。
在 RHEL/Centos 6 中,/etc/inittab 已弃用。那么我该如何确保该进程将重新生成?
答案1
在 RHEL 6 上重新生成脚本,请转到 /etc/init 并创建一个文件
cd /etc/init
vi scriptFileName.conf
并添加此内容
start on stopped rc RUNLEVEL=[12345]
stop on runlevel [!12345]
respawn
exec /you/respawned/script.sh -your -parameters
保存文件然后启动此命令(不带文件的 .conf)
start scriptFileName
就这样!
答案2
我通常使用supervisord。
干净,简单。
这是一个很好的例子:
[program:vmstats]
; this assumes that there's a symlink from vmstats->vmstats-VERSION
command=/apps/vmstats/jdk1.6.0_32/bin/java -Dlog4j.configuration=file:/apps/vmstats/log4j.properties -jar /apps/vmstats/vmstats-2.0.1-jar-with-dependencies.jar
numprocs=1 ; number of processes copies to start (def 1)
directory=/apps/vmstats/ ; directory to cwd to before exec (def no cwd)
autostart=true ; start at supervisord start (default: true)
autorestart=true ; whether/when to restart (default: unexpected)
startsecs=3 ; number of secs prog must stay running (def. 1)
startretries=3 ; max # of serial start failures (default 3)
user=vmstats ; setuid to this UNIX account to run the program
redirect_stderr=true ; redirect proc stderr to stdout (default false)
stdout_logfile=/var/log/vmstats/vmstats-stdout.log ; stdout log path, NONE for none; default AUTO
stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=10 ; # of stdout logfile backups (default 10)
stdout_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0)
stdout_events_enabled=false ; emit events on stdout writes (default false)
stderr_logfile=/var/log/vmstats/vmstats-stderr.log ; stdout log path, NONE for none; default AUTO
stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
stderr_logfile_backups=10 ; # of stderr logfile backups (default 10)
stderr_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0)
stderr_events_enabled=false ; emit events on stderr writes (default false)
你可以在这里看到它: https://github.com/Nordstrom/vmstats/blob/master/supervisord/vmstats.conf