aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Bachelier <laurent@bachelier.name>2010-12-27 17:03:04 +0100
committerLaurent Bachelier <laurent@bachelier.name>2010-12-27 17:03:04 +0100
commitc8faa5ab08647953751ed593cf2efdc69964cae6 (patch)
tree16de8b8cfd13037c1d898322b6a9069c98531808
parentDetects when the lighttpd rewrite rules are changed (diff)
downloadsymfttpd-c8faa5ab08647953751ed593cf2efdc69964cae6.tar.xz
Move the lighttpd-killing to a function
-rw-r--r--lib/PosixTools.php25
-rwxr-xr-xspawn14
2 files changed, 26 insertions, 13 deletions
diff --git a/lib/PosixTools.php b/lib/PosixTools.php
index 8970b46..4cc8a19 100644
--- a/lib/PosixTools.php
+++ b/lib/PosixTools.php
@@ -57,5 +57,30 @@ class PosixTools
self::$custom_path = $custom_path;
}
+ /**
+ * Get a process ID from a file, and kill it, and remove the file either way.
+ * @param $pidfile Path to PID file
+ * @return boolean Success
+ *
+ * @author Laurent Bachelier <laurent@bachelier.name>
+ */
+ static public function killPid($pidfile)
+ {
+ if (file_exists($pidfile))
+ {
+ $pid = intval(trim(file_get_contents($pidfile)));
+ unlink($pidfile);
+ if ($pid)
+ {
+ posix_kill($pid, SIGTERM);
+ log_message('Process '.$pid.' killed');
+
+ return true;
+ }
+ }
+ log_message('No running process found', true);
+
+ return false;
+ }
}
diff --git a/spawn b/spawn
index 5d475eb..94ddb14 100755
--- a/spawn
+++ b/spawn
@@ -33,19 +33,7 @@ if ($options['fork'] && !function_exists('pcntl_fork'))
if (Argument::get('K', 'kill', false))
{
- if (file_exists($options['pidfile']))
- {
- $pid = intval(trim(file_get_contents($options['pidfile'])));
- unlink($options['pidfile']);
- if ($pid)
- {
- posix_kill($pid, SIGTERM);
- log_message('Process '.$pid.' killed');
- exit(0);
- }
- }
- log_message('No running process found', true);
- exit(1);
+ exit(!PosixTools::killPid($options['pidfile']));
}
FileTools::mkdirs($options['config_dir']);