if (posix_kill(-$pgid, SIGTERM) === FALSE) { syslog(LOG_CRIT, "Could not kill {$oldpid}"); exit(1); } } } exit(0); } if (!empty($opts["a"]) && $opts["a"] != "start") { syslog(LOG_CRIT, "Action must be either start or stop"); exit(1); } if ($oldpid > 0 && file_exists("/proc/{$oldpid}")) { syslog(LOG_CRIT, "Process already started: {$oldpid}"); exit(1); } if (!empty($opts["p"])) { $pidPath = $opts["p"]; $pidfile = fopen($pidPath, 'c+'); if (!$pidfile) { syslog(LOG_CRIT, "Cannot open pid file {$pidPath}"); exit(1); } fseek($pidfile, 0); ftruncate($pidfile, 0); fwrite($pidfile, posix_getpid()); fflush($pidfile); fclose($pidfile); } $sync->run(); exit(0);