Permalink
Browse files

Implement stopRunning, a standardized way of killing existing daemons

  • Loading branch information...
1 parent d44259f commit 170cee92951b6781fc3cfe6db6f7bf8c3c28b032 @kvz committed Aug 23, 2012
Showing with 33 additions and 1 deletion.
  1. +33 −1 System/Daemon.php
View
@@ -1292,6 +1292,38 @@ static public function isRunning()
}
+ /**
+ * Stops a previous process with same pidfile that was already running
+ *
+ * @return boolean
+ */
+ static public function stopRunning()
+ {
+ $appPidLocation = self::opt('appPidLocation');
+
+ if (!file_exists($appPidLocation)) {
+ unset($appPidLocation);
+ return false;
+ }
+
+ $pid = self::fileread($appPidLocation);
+ if (!$pid) {
+ return false;
+ }
+
+ // Ping app
+ if (!posix_kill(intval($pid), SIGTERM)) {
+ self::warning('No daemon responded to SIGTERM');
+ return false;
+ } else {
+ self::info('Stopping daemon with PID %s', $pid);
+ }
+
+ // Not responding so unlink pidfile
+ @unlink($appPidLocation);
+
+ return true;
+ }
/**
* Put the running script in background
@@ -1502,7 +1534,7 @@ static protected function _changeIdentity($gid = 0, $uid = 0)
if (!file_exists($filePath)) {
continue;
}
-
+
// Change File GID
$doGid = (filegroup($filePath) != $gid ? $gid : false);
if (false !== $doGid && !@chgrp($filePath, intval($gid))) {

0 comments on commit 170cee9

Please sign in to comment.