From 3004f6493f7b359a6490b7c1191fdf9b3165e6b0 Mon Sep 17 00:00:00 2001 From: jbjohnso Date: Tue, 2 Oct 2012 17:52:18 +0000 Subject: [PATCH] Have xcatd launch process monitor xCAT SSL instance to assure it gets off the ground before exiting git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@13931 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-server/sbin/xcatd | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/xCAT-server/sbin/xcatd b/xCAT-server/sbin/xcatd index bdfe6d0a7..2cfc950b9 100755 --- a/xCAT-server/sbin/xcatd +++ b/xCAT-server/sbin/xcatd @@ -189,16 +189,19 @@ if (xCAT::Utils->isMN()) { `$::XCATROOT/sbin/runsqlcmd`; } - +my $startupchild; +my $startupparent; sub daemonize { chdir('/'); umask 0022; my $pid; + socketpair($startupparent,$startupchild,AF_UNIX,SOCK_STREAM,PF_UNSPEC); if (! defined($pid = xCAT::Utils->xfork)) { xCAT::MsgUtils->message("S","Can't fork: $!"); die; } if ($pid) { + close($startupparent); # the launcher only wants to examing startupchild if ($pidfile) { open(PFILE, '>', $pidfile); print PFILE $pid; @@ -206,10 +209,18 @@ sub daemonize { } else { xCAT::MsgUtils->message("S","xCATd starting as PID $pid"); } + my $result=<$startupchild>; + chomp($result); + unless ($result) { exit (1); } + if ($result ne "SUCCESS") { + xCAT::MsgUtils->message("S","xCATd failed to start: $result"); + exit(1); + } exit; } + close($startupchild); # only want child to report up to parent... if (! open STDIN, '/dev/null') { - xCAT::MsgUtils->message("S","Can't read /dev/null: $!"); + print $startupparent "Can't read /dev/null: $!\n"; die; } open STDOUT, '>/dev/null'; @@ -218,6 +229,7 @@ sub daemonize { $progname = \$0; if (! setsid) { xCAT::MsgUtils->message("S","Can't start new session"); + print $startupparent "Can't start new session\n"; die; } } @@ -852,8 +864,16 @@ unless ($listener) { } xCAT::MsgUtils->message("S","xCAT service unable to open SSL services on $port: $!"); closelog(); + if ($startupparent) { + print $startupparent "Unable to perform socket takeover from existing xCAT instance\n"; + } die "ERROR:Unable to start xCAT service on port $port."; } +if ($startupparent) { + print $startupparent "SUCCESS\n"; +} + + #only write to pid file if we have listener, listener ownership serves as lock to protect integrity open($mainpidfile,">","/var/run/xcat/mainservice.pid"); #if here, everyone else has unlinked mainservicepid or doesn't care print $mainpidfile $$;