create the pid file before doing anything else (#2114)

* create the pid file before doing anything else

* update comment
This commit is contained in:
Andrew Bauer 2018-06-08 07:53:23 -05:00 committed by Isaac Connor
parent 5f35f481c5
commit 61445620aa
1 changed files with 10 additions and 7 deletions

View File

@ -245,6 +245,16 @@ our %terminating_processes;
our $zm_terminate = 0; our $zm_terminate = 0;
sub run { sub run {
# Call this first otherwise stdout/stderror redirects to the pidfile = bad
if ( open(my $PID, '>', ZM_PID) ) {
print($PID $$);
close($PID);
} else {
# Log not initialized at this point so use die instead
die "Can't open pid file at ".ZM_PID."\n";
}
my $fd = 0; my $fd = 0;
while( $fd < POSIX::sysconf(&POSIX::_SC_OPEN_MAX) ) { while( $fd < POSIX::sysconf(&POSIX::_SC_OPEN_MAX) ) {
POSIX::close($fd++); POSIX::close($fd++);
@ -259,13 +269,6 @@ sub run {
."\n" ."\n"
); );
if ( open(my $PID, '>', ZM_PID) ) {
print($PID $$);
close($PID);
} else {
Error("Can't open pid file at " . ZM_PID);
}
# Tell any existing processes to die, wait 1 second between TERM and KILL # Tell any existing processes to die, wait 1 second between TERM and KILL
killAll(1); killAll(1);