/etc/inittab respawn script migrating from RHEL/CentOS 5.x to 6.x

centos6initinittabrhel6upstart

I have a non-forking perl script running as a TCP-sockets daemon (this script is a backend for a multiplayer game) in CentOS 5.7. It is being started and respawned by /etc/inittab:

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

It is being restarted every night by the cronjob:

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

(where the /tmp/pref.pid file is created by the script itself).

This setup has worked well for me since many moons. Now I'm trying to upgrade to CentOS 6.x and have created a new /etc/init/pref.conf file after reading "man 5 init":

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

And can start it with

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

and also see the script running under user afarber with "ps uawx" and listening at port 8080 (as it should) with "netstat -an".

But my problem is that I can't stop or restart the script (and I need that for the nightly cronjob):

# sudo initctl restart pref
initctl: Unknown instance:

# sudo initctl stop pref
initctl: Unknown instance:

Any ideas please?

(And I don't want to install any 3rd party software, like daemontools/Tivoli/etc. – because I want to be my web server to be easily reinstallable and movable to other hosters).

UPDATE: here is what I see –

# 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:

My script has 2 pecularities:

1) When it gets SIGTERM or SIGINT, it writes some data into PostgreSQL and this takes 10-15 seconds

2) When it is started numerous times, then the subsequent runs will fail immediately, because only the 1st instance will be able to listen at the TCP-port 8080

And in /var/log/messages I see:

...
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

is that all maybe the reason and is there something I could do? (maybe somehow delay the subsequent spawns?)

Best Answer

What does 'initctl list' show? Have you tried 'initctl reload-configuration' after creating the job?