Skip to content

Commit

Permalink
pidfile handling improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
timar committed Jan 17, 2021
1 parent 8c400ee commit 60b0fe8
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function getLoolwsdPid()

function isLoolwsdRunning()
{
return getLoolwsdPid();
return file_exists('/proc/' . getLoolwsdPid());
}

function startLoolwsd()
Expand All @@ -70,25 +70,28 @@ function startLoolwsd()
// Extract the AppImage if FUSE is not available
$launchCmd = "bash -c \"( $appImage || $appImage --appimage-extract-and-run ) >/dev/null & disown\"";

// We start a new server, we don't need stale pidfile around
if (file_exists('/tmp/loolwsd.pid'))
unlink('/tmp/loolwsd.pid');

debug_log("Launch the loolwsd server: $launchCmd");
exec($launchCmd, $output, $return);
if ($return)
{
debug_log("Failed to launch server at $appImage.");
}
// wait for the pidfile, prevent second start
while (!file_exists('/tmp/loolwsd.pid'))
sleep(1);
}

function stopLoolwsd()
{
$pid = getLoolwsdPid();
if ($pid)
if (file_exists('/proc/$pid'))
{
debug_log("Stopping the loolwsd server with pid: $pid");
exec("kill -s TERM $pid", $output, $return);
if ($return) {
// no such process?
exec("rm /tmp/loolwsd.pid");
}
exec("kill -s TERM $pid");
}
}

Expand Down

0 comments on commit 60b0fe8

Please sign in to comment.