Alexander Farber
2011-Jun-02 19:46 UTC
[CentOS] Restarting a Perl-script (socket daemon) from /etc/inittab
Hello fellow CentOS sysadmins, I run a small multiplayer card game with around 500 users at peak times. The client is in Flash and the server is in Perl. The Perl server binds to port 8080, i.e. only 1 instance of it can be started (important detail). The Perl server poll()s TCP-sockets and forks only once - at the startup by calling this method: sub daemonize { die "Can not fork: $!\n" unless defined (my $child = fork()); # the parent should die exit 0 if $child; setsid(); open(STDIN, '</dev/null'); open(STDOUT, '>/tmp/pref.txt'); open(STDERR, '>&STDOUT'); chdir('/'); umask(0); } It runs on CentOS 5.6 Linux / 64 bit, PostgreSQL 8.4.8 and Perl 5.8.8. Because my budget is small and I had enough troubles already, I want to use as little additional software as possible - so that I can change hosters or reinstall my cheapo server quickly. That is why I for example just log to /tmp/pref.txt instead of installing syslog-ng. And that is why I'd like to use /etc/inittab for restarting my Perl daemon. My Perl daemon runs mostly stable, but approx. once a week it can crash with a May 29 11:06:46 myhost kernel: pref.pl[3113]: segfault at 00007fffa21e6fd8 rip 0000003cce274460 rsp 00007fffa21e6fd0 error 6 Since I'm tired of restarting the server manually, I've tried to add it to the /etc/inittab: pref:3:respawn:/bin/su -c '/usr/local/pref/pref.pl' nobody (and I've added a nightly cronjob to "pkill pref.pl" in the hope to refresh perl this way). Unfortunately this does not work as expected - in the /var/log/messages I see that the script is being started again and again every 5 mins: Jun 2 18:55:56 myhost init: Id "pref" respawning too fast: disabled for 5 minutes What am I doing wrong here? I was hoping to being able to use /etc/inittab here, because I remember using it for a similar situation at work few years ago (also with a Perl daemon) and it worked well then... Thank you! Alex P.S. I've also posted my question at http://serverfault.com/questions/276428/restarting-a-perl-script-socket-daemon-from-etc-inittab
m.roth at 5-cent.us
2011-Jun-02 19:52 UTC
[CentOS] Restarting a Perl-script (socket daemon) from /etc/inittab
Alexander Farber wrote:> Hello fellow CentOS sysadmins, > > I run a small multiplayer card game > with around 500 users at peak times. > > The client is in Flash and the server is in Perl.<snip>> My Perl daemon runs mostly stable, but > approx. once a week it can crash with a > > May 29 11:06:46 myhost kernel: pref.pl[3113]: > segfault at 00007fffa21e6fd8 rip 0000003cce274460 > rsp 00007fffa21e6fd0 error 6<snip> Ok, here's the more significant question: why's it SEGV'ing? What's at line 3113 that could segv? mark, was a programmer longer than I've been a sysadmin
Les Mikesell
2011-Jun-02 20:10 UTC
[CentOS] Restarting a Perl-script (socket daemon) from /etc/inittab
On 6/2/2011 2:46 PM, Alexander Farber wrote:> > The Perl server poll()s TCP-sockets and forks > only once - at the startup by calling this method: > > sub daemonize { > die "Can not fork: $!\n" unless defined (my $child = fork()); > # the parent should die > exit 0 if $child;[....]> Since I'm tired of restarting the server manually, > I've tried to add it to the /etc/inittab: > > pref:3:respawn:/bin/su -c '/usr/local/pref/pref.pl' nobody > > (and I've added a nightly cronjob to > "pkill pref.pl" in the hope to refresh perl this way). > > Unfortunately this does not work as expected - > in the /var/log/messages I see that the script > is being started again and again every 5 mins: > > Jun 2 18:55:56 myhost init: Id "pref" > respawning too fast: disabled for 5 minutes > > What am I doing wrong here?It needs to not fork/exit on its own if you want init to respawn when it exits. -- Les Mikesell lesmikesell at gmail.com
Maybe Matching Threads
- Migrating CentOS 5 -> 6: where to put /etc/inittab respawn scripts?
- Removing respawning process from inittab w/o killing it
- inittab - huh what's it good for?
- /etc/inittab: Serial access/ Console Server
- Patch to allow openssh-2.2.0-p1 to be started from /etc/inittab