function stop_sync_client() { $unix = new unix(); if (!is_file($unix->CYRUS_SYNC_CLIENT_BIN_PATH())) { return; } $pid = PID_NUM(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} - sync_client - service already stopped...\n"; } return; } $pid = sync_client_pid(); $nohup = $unix->find_program("nohup"); $php5 = $unix->LOCATE_PHP5_BIN(); $kill = $unix->find_program("kill"); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} - sync_client - service Shutdown pid {$pid}...\n"; } unix_system_kill($pid); for ($i = 0; $i < 5; $i++) { $pid = sync_client_pid(); if (!$unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} - sync_client - Service Waiting pid:{$pid} {$i}/5...\n"; } sleep(1); } $pid = sync_client_pid(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} - sync_client - Service success...\n"; } return; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} - sync_client - service Shutdown - force - pid {$pid}...\n"; } unix_system_kill_force($pid); for ($i = 0; $i < 5; $i++) { $pid = sync_client_pid(); if (!$unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} - sync_client - service Waiting pid:{$pid} {$i}/5...\n"; } sleep(1); } if ($unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} - sync_client - service Failed...\n"; } return; } }
function SERVICE_STOP($aspid = false) { $unix = new unix(); $sock = new sockets(); $socket = "/var/run/mysqld/mysqld.sock"; $mysqlbin = $unix->LOCATE_mysqld_bin(); $php5 = $unix->LOCATE_PHP5_BIN(); $nohup = $unix->find_program("nohup"); $mysqladmin = $unix->find_program("mysqladmin"); $kill = $unix->find_program("kill"); $pgrep = $unix->find_program("pgrep"); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = @file_get_contents($pidfile); $kill = $unix->find_program("kill"); if (!$aspid) { if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); echo "Stopping MySQL...............: This script is already executed PID: {$pid} since {$time}Mn\n"; if ($time < 5) { if (!$GLOBALS["FORCE"]) { return; } } unix_system_kill_force($pid); } @file_put_contents($pidfile, getmypid()); } $pid = PID_NUM(); if ($GLOBALS["VERBOSE"]) { echo "DEBUG:: PID RETURNED {$pid}\n"; } $unix->ToSyslog("MySQL: Stopping MySQL server"); if (!$unix->process_exists($pid, $mysqlbin)) { echo "Stopping MySQL...............: Already stopped\n"; return; } $q = new mysql(); $q2 = new mysql_squid_builder(); $q2->MEMORY_TABLES_DUMP(); if (is_file($mysqladmin)) { if (is_file($socket)) { $cmds[] = "nohup"; $cmds[] = $mysqladmin; $cmds[] = "--user={$q->mysql_admin}"; if ($q->mysql_password != null) { $password = $q->mysql_password; $password = $unix->shellEscapeChars($password); $cmds[] = "--password={$password}"; } $cmds[] = "--socket={$socket}"; $cmds[] = "shutdown"; $cmd = @implode(" ", $cmds); $cmd = $cmd . " >/dev/null 2>&1 &"; echo "Stopping MySQL...............: Stopping smoothly mysqld pid:{$pid}\n"; if ($GLOBALS["VERBOSE"]) { echo "[VERBOSE]: {$cmd}\n"; } for ($i = 0; $i < 10; $i++) { sleep(1); $pid = PID_NUM(); if (!$unix->process_exists($pid, $mysqlbin)) { break; } echo "Stopping MySQL...............: Stopping, please wait {$i}/10\n"; } } } $pid = PID_NUM(); if (!$unix->process_exists($pid, $mysqlbin)) { echo "Stopping MySQL...............: Stopped\n"; system_admin_events("Success to STOP MySQL server", __FUNCTION__, __FILE__, __LINE__, "services"); return; } mysql_admin_mysql(0, "Stopping MySQL service PID {$pid}", null, __FILE__, __LINE__); echo "Stopping MySQL...............: killing smoothly PID {$pid}\n"; unix_system_kill($pid); for ($i = 0; $i < 5; $i++) { sleep(1); $pid = PID_NUM(); if (!$unix->process_exists($pid, $mysqlbin)) { break; } } if (!$unix->process_exists($pid, $mysqlbin)) { echo "Stopping MySQL...............: Stopped\n"; system_admin_events("Success to STOP MySQL server", __FUNCTION__, __FILE__, __LINE__, "services"); return; } echo "Stopping MySQL...............: Force killing PID {$pid}\n"; unix_system_kill_force($pid); for ($i = 0; $i < 5; $i++) { sleep(1); $pid = PID_NUM(); if (!$unix->process_exists($pid, $mysqlbin)) { break; } } if (!$unix->process_exists($pid, $mysqlbin)) { echo "Stopping MySQL...............: Stopped\n"; system_admin_events("Success to STOP MySQL server", __FUNCTION__, __FILE__, __LINE__, "services"); return; } echo "Stopping MySQL...............: failed\n"; }
function MultiplesInstances_stop($hostname) { $unix = new unix(); $pid = MultiplesInstancesPID($hostname); if (!$unix->process_exists($pid)) { echo "{$GLOBALS["deflog_sstop"]} {$hostname} already stopped\n"; return; } echo "{$GLOBALS["deflog_sstop"]} {$hostname} stopping pid {$pid}\n"; unix_system_kill($pid); for ($i = 0; $i < 20; $i++) { $pid = MultiplesInstancesPID($hostname); if (!$unix->process_exists($pid)) { echo "{$GLOBALS["deflog_sstop"]} {$hostname} stopped\n"; break; } echo "{$GLOBALS["deflog_sstop"]} {$hostname} waiting pid {$pid}\n"; if ($unix->process_exists($pid)) { unix_system_kill_force($pid); sleep(1); continue; } break; } }
function stop($aspid = false) { $sock = new sockets(); $unix = new unix(); $GLOBALS["CLASS_UNIX"] = $unix; if (!$aspid) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Already task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); } $pid = mailarchive_pid(); if (!$unix->process_exists($pid)) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: Mail Archiver already stopped...\n"; } return; } $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: Mail Archiver pid {$pid} (run since {$time}Mn)...\n"; } $kill = $unix->find_program("kill"); unix_system_kill($pid); for ($i = 0; $i < 5; $i++) { $pid = mailarchive_pid(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: Mail Archiver (Perl method) stopped...\n"; } break; } sleep(1); } $pid = mailarchive_pid(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: Mail Archiver (Perl method) success...\n"; } @unlink("/var/run/maildump/maildump.socket"); } else { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: Mail Archiver (Perl method) failed to stop..\n"; } } }
function stop($aspid = false) { $unix = new unix(); if (!$aspid) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service Already Artica task running PID {$pid} since {$time}mn\n"; } build_progress_restart("{stopping_service} {failed}", 110); return; } @file_put_contents($pidfile, getmypid()); } $pid = $GLOBALS["MONIT_CLASS"]->PID_NUM(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service already stopped...\n"; } build_progress_restart("{stopping_service} {success}", 20); return true; } $pid = $GLOBALS["MONIT_CLASS"]->PID_NUM(); $nohup = $unix->find_program("nohup"); $php5 = $unix->LOCATE_PHP5_BIN(); $kill = $unix->find_program("kill"); build_progress_restart("{stopping_service}", 16); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} unmonitor all processes\n"; } exec($GLOBALS["MONIT_CLASS"]->stop_cmdline . " 2>&1", $results); sleep(1); build_progress_restart("{stopping_service}", 17); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service Shutdown pid {$pid}...\n"; } unix_system_kill($pid); for ($i = 0; $i < 5; $i++) { $pid = $GLOBALS["MONIT_CLASS"]->PID_NUM(); if (!$unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service waiting pid:{$pid} {$i}/5...\n"; } sleep(1); } build_progress_restart("{stopping_service}", 18); $pid = $GLOBALS["MONIT_CLASS"]->PID_NUM(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service success...\n"; } build_progress_restart("{stopping_service} {success}", 20); return true; } build_progress_restart("{stopping_service}", 19); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service shutdown - force - pid {$pid}...\n"; } unix_system_kill_force($pid); for ($i = 0; $i < 5; $i++) { $pid = $GLOBALS["MONIT_CLASS"]->PID_NUM(); if (!$unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service waiting pid:{$pid} {$i}/5...\n"; } sleep(1); } if ($unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service failed...\n"; } build_progress_restart("{stopping_service} {failed}", 110); return false; } build_progress_restart("{stopping_service} {success}", 20); return true; }
function stop($aspid = false) { $unix = new unix(); if (!$aspid) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); } $spawn_fcgi = $unix->find_program("spawn-fcgi"); if (!is_file($spawn_fcgi)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} not installed\n"; } return; } $pid = DEFAULT_PID(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} already stopped...\n"; } return; } $pid = DEFAULT_PID(); $nohup = $unix->find_program("nohup"); $php5 = $unix->LOCATE_PHP5_BIN(); $lighttpd_bin = $unix->find_program("lighttpd"); $kill = $unix->find_program("kill"); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Shutdown pid {$pid}...\n"; } unix_system_kill($pid); for ($i = 0; $i < 5; $i++) { $pid = DEFAULT_PID(); if (!$unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} waiting pid:{$pid} {$i}/5...\n"; } sleep(1); } $pid = DEFAULT_PID(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} success...\n"; } return; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} shutdown - force - pid {$pid}...\n"; } unix_system_kill_force($pid); for ($i = 0; $i < 5; $i++) { $pid = DEFAULT_PID(); if (!$unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} waiting pid:{$pid} {$i}/5...\n"; } sleep(1); } if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} success...\n"; } return; } else { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} failed...\n"; } } }
function stop() { $unix = new unix(); $sock = new sockets(); $masterbin = $unix->find_program("ntopng"); if (!is_file($masterbin)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Not installed\n"; } return; } $pid = ntopng_pid(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Already stopped...\n"; } return; } $nohup = $unix->find_program("nohup"); $php5 = $unix->LOCATE_PHP5_BIN(); $kill = $unix->find_program("kill"); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Shutdown pid {$pid}...\n"; } unix_system_kill($pid); for ($i = 0; $i < 5; $i++) { $pid = ntopng_pid(); if (!$unix->process_exists($pid)) { break; } unix_system_kill($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} waiting pid:{$pid} {$i}/5...\n"; } sleep(1); } $pid = ntopng_pid(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} success...\n"; } return; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} shutdown - force - pid {$pid}...\n"; } unix_system_kill_force($pid); for ($i = 0; $i < 5; $i++) { $pid = ntopng_pid(); if (!$unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} waiting pid:{$pid} {$i}/5...\n"; } unix_system_kill_force($pid); sleep(1); } if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} success stopped...\n"; } return; } else { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} failed...\n"; } } }
function stop_instance($ID) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".{$ID}.pid"; $pid = @file_get_contents($pidfile); $unix = new unix(); if ($unix->process_exists($pid, basename(__FILE__))) { echo "Starting......: " . date("H:i:s") . " load-balancer engine Already executed PID {$pid}...\n"; return; } @file_put_contents($pidfile, getmypid()); $unix = new unix(); $q = new mysql(); $kill = $unix->find_program("kill"); $pid = cross_pid($ID); if (!$unix->process_exists($pid)) { echo "Stopping Crossroads Daemon...: instance ID:{$ID} already stopped\n"; return; } echo "Stopping Crossroads Daemon...: instance ID:{$ID} PID {$pid}\n"; if (is_numeric($pid)) { unix_system_kill($pid); } for ($i = 0; $i < 5; $i++) { sleep(1); if (!$unix->process_exists($pid)) { echo "Stopping Crossroads Daemon...: instance ID:{$ID} stopped\n"; crossroads_events("Instance ID:{$ID} success to stop", $ID, __FUNCTION__, __LINE__); return; } $pid = cross_pid($ID); if (is_numeric($pid)) { unix_system_kill($pid); } } $pid = cross_pid($ID); if ($unix->process_exists($pid)) { echo "Stopping Crossroads Daemon...: instance ID:{$ID} Force to kill it !\n"; if (is_numeric($pid)) { unix_system_kill_force($pid); } } $pid = cross_pid($ID); if ($unix->process_exists($pid)) { echo "Stopping Crossroads Daemon...: instance ID:{$ID} failed\n"; crossroads_events("Unable to stop instance", $ID, __FUNCTION__, __LINE__); } else { echo "Stopping Crossroads Daemon...: instance ID:{$ID} success\n"; } }
function stop($aspid = false) { $unix = new unix(); if (!$aspid) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); } $pid = PID_NUM(); if (!$unix->process_exists($pid)) { build_progress_rs("{stopping_service}", 30); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service already stopped...\n"; } return true; } $nohup = $unix->find_program("nohup"); $php5 = $unix->LOCATE_PHP5_BIN(); $kill = $unix->find_program("kill"); build_progress_rs("{stopping_service}", 15); if (!ifInitScript()) { shell_exec("{$php5} /usr/share/artica-postfix/exec.initslapd.php --influx"); } $cmd = "/etc/init.d/influx-db stop"; if ($GLOBALS["VERBOSE"]) { echo "{$cmd}\n"; } shell_exec($cmd); $pid = PID_NUM(); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service Shutdown pid {$pid}...\n"; } unix_system_kill($pid); for ($i = 0; $i < 5; $i++) { build_progress_rs("{stopping_service}", 15 + $i); $pid = PID_NUM(); if (!$unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service waiting pid:{$pid} {$i}/5...\n"; } sleep(1); } if (test_listen_port()) { for ($i = 0; $i < 5; $i++) { build_progress_rs("{stopping_service} {waiting_port_to_be_closed}", 25); if (!test_listen_port()) { break; } if (!$unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service waiting socket {$i}/5...\n"; } sleep(1); } } $pid = PID_NUM(); if (!$unix->process_exists($pid)) { build_progress_rs("{stopping_service}", 30); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service success...\n"; } return true; } build_progress_rs("{stopping_service}", 30); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service shutdown - force - pid {$pid}...\n"; } unix_system_kill_force($pid); for ($i = 0; $i < 5; $i++) { build_progress_rs("{stopping_service}", 30 + $i); $pid = PID_NUM(); if (!$unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service waiting pid:{$pid} {$i}/5...\n"; } sleep(1); } if ($unix->process_exists($pid)) { build_progress_rs("{stopping_service} {failed}", 110); squid_admin_mysql(0, "Failed to start Statistics Engine", __FILE__, __LINE__); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service failed...\n"; } return; } return true; }
function virtual_delete() { $unix = new unix(); $virtname = $_GET["virtual-delete"]; $nic = $_GET["nic"]; $pidfile = "/var/run/{$virtname}.pid"; $ipbin = $unix->find_program("ip"); $ifconfig = $unix->find_program("ifconfig"); $nohup = $unix->find_program("nohup"); $php5 = $unix->LOCATE_PHP5_BIN(); $pid = $unix->get_pid_from_file($pidfile); $kill = $unix->find_program("kill"); if ($unix->process_exists($pid)) { unix_system_kill($pid); sleep(1); } if ($unix->process_exists($pid)) { unix_system_kill_force($pid); sleep(1); } $cmd = "{$ipbin} route flush table {$virtname}"; writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__); shell_exec($cmd); $cmd = "/usr/share/artica-postfix/bin/rt_tables.pl --remove-name {$virtname} >/dev/null 2>&1"; writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__); shell_exec($cmd); $cmd = "{$ifconfig} {$virtname} down"; writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__); shell_exec($cmd); $cmd = trim("{$nohup} {$php5} /usr/share/artica-postfix/exec.vde.php --reconfigure-switch {$nic} >/dev/null 2>&1 &"); writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__); shell_exec($cmd); }
function stop($aspid = false) { $unix = new unix(); if (is_file("/etc/artica-postfix/FROM_ISO")) { if ($unix->file_time_min("/etc/artica-postfix/FROM_ISO") < 1) { return; } } $scriptlog = null; if ($GLOBALS["BYSCRIPT"]) { $scriptlog = " by init.d script"; } if (!$aspid) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); } $pid = LIGHTTPD_PID(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: Framework service already stopped...\n"; } return; } $pid = LIGHTTPD_PID(); if ($GLOBALS["MONIT"]) { @file_put_contents("/var/run/lighttpd/framework.pid", $pid); return; } $nohup = $unix->find_program("nohup"); $php5 = $unix->LOCATE_PHP5_BIN(); $lighttpd_bin = $unix->find_program("lighttpd"); $kill = $unix->find_program("kill"); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: Framework shutdown pid {$pid}...\n"; } unix_system_kill($pid); for ($i = 0; $i < 5; $i++) { $pid = LIGHTTPD_PID(); if (!$unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service waiting pid:{$pid} {$i}/5...\n"; } sleep(1); } $pid = LIGHTTPD_PID(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: Framework service success...\n"; } killallphpcgi(); return; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: Framework shutdown - force - pid {$pid}...\n"; } unix_system_kill_force($pid); for ($i = 0; $i < 5; $i++) { $pid = LIGHTTPD_PID(); if (!$unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service waiting pid:{$pid} {$i}/5...\n"; } sleep(1); } if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: Framework service success...\n"; } FrmToSyslog("Success service stopped {$scriptlog}"); killallphpcgi(); return; } else { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: Framework service failed...\n"; } } }
function cgred_stop($nomypidcheck = false) { if ($GLOBALS["VERBOSE"]) { echo "Starting......: " . date("H:i:s") . " cgroups: DEBUG:: " . __FUNCTION__ . " START\n"; } $unix = new unix(); if (!$nomypidcheck) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = @file_get_contents($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $trace = debug_backtrace(); if (isset($trace[1])) { $called = " called by " . basename($trace[1]["file"]) . " {$trace[1]["function"]}() line {$trace[1]["line"]}"; } echo "Starting......: " . date("H:i:s") . " cgroups: cgred_stop() function Already running pid {$pid}, aborting {$called}\n"; return; } @file_put_contents($pidfile, getmypid()); } $cgrulesengd = $unix->find_program("cgrulesengd"); $kill = $unix->find_program("kill"); if (!is_file($cgrulesengd)) { echo "Stopping cgroups.............: CGroup Rules Engine Daemon no such binary\n"; return; } $pid = $unix->PIDOF($cgrulesengd); if (!$unix->process_exists($pid)) { echo "Stopping cgroups.............: CGroup Rules Engine Daemon already stopped\n"; return; } unix_system_kill($pid); for ($i = 0; $i < 6; $i++) { $pid = $unix->PIDOF($cgrulesengd); if (!$unix->process_exists($pid)) { break; } sleep(1); } $pid = $unix->PIDOF($cgrulesengd); if (!$unix->process_exists($pid)) { echo "Stopping cgroups.............: CGroup Rules Engine successfully stopped\n"; } else { echo "Stopping cgroups.............: CGroup Rules Engine failed to stop\n"; } }
function stop($nopid = false) { $users = new usersMenus(); $unix = new unix(); if (!$users->ETTERCAP_INSTALLED) { echo "ArpSpoofing.........: [STOP]: Ettercap, not installed...\n"; return; } $kill = $unix->find_program("kill"); if (!$nopid) { $me = basename(__FILE__); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, $me)) { $time = $unix->PROCCESS_TIME_MIN($pid); echo "ArpSpoofing.........: [START]: Ettercap, Already start instance executed PID {$pid} since {$time}Mn...\n"; return; } @file_put_contents($pidfile, getmypid()); } $pids = GetAllPids(); if (count($pids) == 0) { echo "ArpSpoofing.........: [STOP]: Ettercap, no instance in memory\n"; return; } while (list($pid, $ruleid) = each($pids)) { echo "ArpSpoofing.........: [STOP]: stopping smoothly pid {$pid} for rule {$ruleid}\n"; unix_system_HUP($pid); unix_system_kill($pid); } for ($i = 0; $i < 10; $i++) { $pids = GetAllPids(); while (list($pid, $ruleid) = each($pids)) { if (!$unix->process_exists($pid)) { echo "ArpSpoofing.........: [STOP]: pid {$pid} for rule {$ruleid} stopped...\n"; unset($pids[$pid]); continue; } echo "ArpSpoofing.........: [STOP]: pid {$pid} for rule {$ruleid} still alive...\n"; } if (count($pids) == 0) { break; } sleep(1); } $pids = GetAllPids(); if (count($pids) > 0) { reset($pids); while (list($pid, $ruleid) = each($pids)) { echo "ArpSpoofing.........: [STOP]: pid {$pid} for rule {$ruleid} force stopping...\n"; unix_system_kill_force($pid); } } $pids = GetAllPids(); if (count($pids) > 0) { reset($pids); while (list($pid, $ruleid) = each($pids)) { echo "ArpSpoofing.........: [STOP]: pid {$pid} for rule {$ruleid} failed stopping...\n"; } } echo "ArpSpoofing.........: [STOP]: DONE...\n"; }
function multiples_stop() { $GLOBALS["CLASS_UNIX"] = new unix(); $pgrep = $GLOBALS["CLASS_UNIX"]->find_program("pgrep"); $xr = $GLOBALS["CLASS_UNIX"]->find_program("xr"); $kill = $GLOBALS["CLASS_UNIX"]->find_program("kill"); $pattern = "{$pgrep} -l -f \"{$xr}\" 2>&1"; exec($pattern, $results); while (list($index, $line) = each($results)) { if ($GLOBALS["VERBOSE"]) { echo "Stopping Crossroads Daemon...: {$line}\n"; } if (preg_match("#^([0-9]+).+?pgrep#", $line)) { if ($GLOBALS["VERBOSE"]) { echo "Stopping Crossroads Daemon...: pgrep line, continue\n"; } continue; } if (preg_match("#^([0-9]+).+?18501#", $line)) { if ($GLOBALS["VERBOSE"]) { echo "Stopping Crossroads Daemon...: Match master instance, continue\n"; } continue; } if (!preg_match("#^([0-9]+)\\s+#", $line, $re)) { continue; } if ($GLOBALS["VERBOSE"]) { echo "Stopping Crossroads Daemon...: found pid: {$re[1]}\n"; } if ($GLOBALS["CLASS_UNIX"]->process_exists($re[1])) { echo "Stopping Crossroads Daemon...: multiple instance PID {$re[1]}\n"; unix_system_kill($re[1]); for ($i = 0; $i < 5; $i++) { sleep(1); if (!$GLOBALS["CLASS_UNIX"]->process_exists($re[1])) { echo "Stopping Crossroads Daemon...: multiple success PID {$re[1]}...\n"; break; } } } } }
function stop($aspid = false) { $unix = new unix(); if (!$aspid) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); } $pid = PID_NUM(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service already stopped...\n"; } return; } $pid = PID_NUM(); $nohup = $unix->find_program("nohup"); $php5 = $unix->LOCATE_PHP5_BIN(); $kill = $unix->find_program("kill"); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service Shutdown pid {$pid}...\n"; } unix_system_kill($pid); for ($i = 0; $i < 5; $i++) { $pid = PID_NUM(); if (!$unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service waiting pid:{$pid} {$i}/5...\n"; } sleep(1); } $pid = PID_NUM(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service success...\n"; } return; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service shutdown - force - pid {$pid}...\n"; } unix_system_kill_force($pid); for ($i = 0; $i < 5; $i++) { $pid = PID_NUM(); if (!$unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service waiting pid:{$pid} {$i}/5...\n"; } sleep(1); } if ($unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service failed...\n"; } return; } $sock = new sockets(); $maillog_path = $sock->GET_INFO("maillog_path"); $tail = $unix->find_program("tail"); if (strlen($maillog_path) == 0) { shell_exec("/usr/share/artica-postfix/bin/artica-install --whereis-maillog >/dev/null 2>&1"); $maillog_path = $sock->GET_INFO("maillog_path"); } if (strlen($maillog_path) == 0) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Unable to find mail.log path\n"; } return; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} mail.log: {$maillog_path}\n"; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} find ghost processes\n"; } for ($i = 0; $i < 10; $i++) { $pid = PID_NUM(); if (!$unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Kill ghost {$pid} process\n"; } unix_system_kill_force($pid); } }
function stop_recursor() { $sock = new sockets(); $unix = new unix(); $DisablePowerDnsManagement = $sock->GET_INFO("DisablePowerDnsManagement"); if (!is_numeric($DisablePowerDnsManagement)) { $DisablePowerDnsManagement = 0; } $nohup = $unix->find_program("nohup"); $recursorbin = $unix->find_program("pdns_recursor"); $kill = $unix->find_program("kill"); if ($DisablePowerDnsManagement == 1) { echo "Stopping......: " . date("H:i:s") . "PowerDNS Recursor DisablePowerDnsManagement={$DisablePowerDnsManagement}, aborting task\n"; return; } if (!is_file($recursorbin)) { echo "Stopping......: " . date("H:i:s") . "PowerDNS Recursor Not installed, aborting task\n"; } $pid = pdns_recursor_pid(); if (!$unix->process_exists($pid)) { echo "Stopping......: " . date("H:i:s") . "PowerDNS Recursor Already stopped\n"; return; } $pidtime = $unix->PROCCESS_TIME_MIN($pid); echo "Stopping......: " . date("H:i:s") . "PowerDNS Recursor pid {$pid} running since {$pidtime}mn\n"; unix_system_kill($pid); sleep(1); $pid = pdns_recursor_pid(); if ($unix->process_exists($pid)) { for ($i = 0; $i < 5; $i++) { echo "Stopping......: " . date("H:i:s") . "PowerDNS Recursor waiting pid {$pid} top stop " . ($i + 1) . "/5\n"; unix_system_kill($pid); $pid = pdns_recursor_pid(); if (!$unix->process_exists($pid)) { break; } } } $pid = pdns_recursor_pid(); if ($unix->process_exists($pid)) { echo "Stopping......: " . date("H:i:s") . "PowerDNS Recursor force killing pid {$pid}\n"; unix_system_kill_force($pid); if ($unix->process_exists($pid)) { for ($i = 0; $i < 5; $i++) { echo "Stopping......: " . date("H:i:s") . "PowerDNS Recursor waiting pid {$pid} top stop " . ($i + 1) . "/5\n"; unix_system_kill_force($pid); $pid = pdns_recursor_pid(); if (!$unix->process_exists($pid)) { break; } } } } $pid = pdns_recursor_pid(); if ($unix->process_exists($pid)) { echo "Stopping......: " . date("H:i:s") . "PowerDNS Recursor Failed to stop\n"; } else { echo "Stopping......: " . date("H:i:s") . "PowerDNS Recursor success\n"; } }
function stop($aspid = false) { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; if (!$aspid) { $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: Already task running PID {$pid} since {$time}mn\n"; } return; } } @file_put_contents($pidfile, getmypid()); $pid = XZARAFA_GATEWAY_PID(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: zarafa-gateway already stopped...\n"; } return; } $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: zarafa-gateway Daemon with a ttl of {$time}mn\n"; } $kill = $unix->find_program("kill"); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: zarafa-gateway killing smoothly PID {$pid}...\n"; } unix_system_kill($pid); sleep(1); for ($i = 1; $i < 10; $i++) { $pid = XZARAFA_GATEWAY_PID(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: zarafa-gateway pid {$pid} successfully stopped ...\n"; } break; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: zarafa-gateway wait PID {$pid} {$i}/10\n"; } unix_system_kill($pid); sleep(1); } $pid = XZARAFA_GATEWAY_PID(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: zarafa-gateway daemon success...\n"; } return; } for ($i = 1; $i < 120; $i++) { $pid = XZARAFA_GATEWAY_PID(); if ($unix->process_exists($pid)) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: zarafa-gateway Force KILL {$pid} with a ttl of {$time}mn\n"; } unix_system_kill_force($pid); } else { break; } } $pid = XZARAFA_GATEWAY_PID(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: zarafa-gateway daemon success...\n"; } return; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: zarafa-gateway daemon failed...\n"; } }
function stop() { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = @file_get_contents($pidfile); $kill = $unix->find_program("kill"); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); echo "Stopping Zarafa LMTP dagent: This script is already executed PID: {$pid} since {$time}Mn\n"; if ($time < 5) { if (!$GLOBALS["FORCE"]) { return; } } unix_system_kill_force($pid); } @file_put_contents($pidfile, getmypid()); echo "\n"; $pidfile = "/var/run/zarafa-dagent.pid"; echo "Stopping Zarafa LMTP dagent: Pid file: /var/run/zarafa-dagent.pid\n"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid)) { echo "Stopping Zarafa LMTP dagent: Pid {$pid}\n"; unix_system_kill($pid); for ($i = 0; $i < 8; $i++) { sleep(1); if ($unix->process_exists($pid)) { echo "Stopping Zarafa LMTP dagent: {$pid} still running...\n"; } else { break; } } } if ($unix->process_exists($pid)) { echo "Stopping Zarafa LMTP dagent: Force kill Pid {$pid}\n"; unix_system_kill_force($pid); for ($i = 0; $i < 5; $i++) { sleep(1); if ($unix->process_exists($pid)) { echo "Stopping Zarafa LMTP dagent: {$pid} still running...\n"; } else { break; } } } if ($unix->process_exists($pid)) { echo "Stopping Zarafa LMTP dagent: Failed...\n"; return; } $pidof = $unix->find_program("pidof"); $binpath = $unix->find_program("zarafa-dagent"); $results = exec("pidof /usr/bin/zarafa-dagent 2>&1"); $tr = explode(" ", $results); while (list($num, $int) = each($tr)) { if (!is_numeric($int)) { continue; } echo "Stopping Zarafa LMTP dagent: Force kill Ghost daemon pid {$int}\n"; unix_system_kill_force($int); } echo "Stopping Zarafa LMTP dagent: Done...\n"; }
function stop($aspid = false) { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; if (!$aspid) { $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Already task running PID {$pid} since {$time}mn\n"; } return; } } @file_put_contents($pidfile, getmypid()); $pid = PID_NUM(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} already stopped...\n"; } return; } $apache2ctl = $unix->LOCATE_APACHE_CTL(); $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} with a ttl of {$time}mn\n"; } $kill = $unix->find_program("kill"); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} killing smoothly PID {$pid} ( {$apache2ctl} )...\n"; } $results = array(); exec("{$apache2ctl} -f /etc/zarafa/httpd.conf -k stop 2>&1", $results); while (list($index, $dir) = each($results)) { if (preg_match("#[0-9]+.*?not running#", $dir)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} killing \"forced\" PID {$pid}...\n"; } unix_system_kill($pid); break; } } sleep(1); for ($i = 1; $i < 10; $i++) { $pid = PID_NUM(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Successfully stopped ...\n"; } break; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} wait pid {$pid} {$i}/60\n"; } shell_exec("{$apache2ctl} -f /etc/zarafa/httpd.conf -k kill >/dev/null 2>&1"); sleep(1); } $pid = PID_NUM(); if ($unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} killing \"forced\" PID {$pid}...\n"; } unix_system_kill($pid); sleep(1); for ($i = 1; $i < 10; $i++) { $pid = PID_NUM(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Successfully stopped ...\n"; } break; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} wait {$i}/60\n"; } sleep(1); } } if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} daemon success...\n"; } return; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} daemon failed...\n"; } }
function stop_ldap($aspid = false) { if ($GLOBALS["MONIT"]) { xsyslog("Not accept a stop order from MONIT process"); return; } $sock = new sockets(); $users = new usersMenus(); $ldaps = array(); $unix = new unix(); $kill = $unix->find_program("kill"); $slapd = $unix->find_program("slapd"); $pgrep = $unix->find_program("pgrep"); $SLAPD_PID_FILE = $unix->SLAPD_PID_PATH(); $MYPID_FILE = "/etc/artica-postfix/pids/stop_ldap.pid"; if ($users->ZARAFA_INSTALLED) { stop_zarafa(); } if (!$aspid) { $pid = $unix->get_pid_from_file($MYPID_FILE); if ($unix->process_exists($pid, basename(__FILE__))) { $pidtime = $unix->PROCCESS_TIME_MIN($pid); echo "slapd: [INFO] Artica task already running pid {$pid} since {$pidtime}mn\n"; if ($pidtime > 10) { echo "slapd: [INFO] Killing this Artica task...\n"; unix_system_kill_force($pid); } else { die; } } @unlink($MYPID_FILE); @file_put_contents($MYPID_FILE, getmypid()); } $pid = $unix->get_pid_from_file($SLAPD_PID_FILE); $pid = $unix->get_pid_from_file($SLAPD_PID_FILE); if ($unix->process_exists($pid)) { $timeDaemon = $unix->PROCESS_TTL($pid); $unix->ToSyslog("Stopping the OpenLDAP daemon running since {$timeDaemon}Mn", false, basename(__FILE__)); echo "slapd: [INFO] slapd shutdown ldap server PID:{$pid}...\n"; unix_system_kill($pid); } else { $pid = $unix->PIDOF($slapd); if ($unix->process_exists($pid)) { echo "slapd: [INFO] slapd shutdown ldap server PID:{$pid}...\n"; unix_system_kill($pid); } } for ($i = 0; $i < 10; $i++) { $pid = intval($unix->get_pid_from_file($SLAPD_PID_FILE)); if ($pid == 0) { break; } restart_ldap_progress("{stopping_service} stop PID:{$pid}", 20); if ($unix->process_exists($pid)) { echo "slapd: [INFO] slapd waiting the server to stop PID:{$pid}...\n"; sleep(1); continue; } $pid = $unix->PIDOF($slapd); if ($unix->process_exists($pid)) { echo "slapd: [INFO] slapd waiting the server to stop PID:{$pid}...\n"; sleep(1); continue; } } $pid = $unix->get_pid_from_file($SLAPD_PID_FILE); if ($unix->process_exists($pid)) { echo "slapd: [INFO] slapd PID:{$pid} still exists, kill it...\n"; unix_system_kill_force($pid); } $pid = $unix->get_pid_from_file($SLAPD_PID_FILE); if ($unix->process_exists($pid)) { echo "slapd: [INFO] slapd PID:{$pid} still exists, start the force kill procedure...\n"; } restart_ldap_progress("{stopping_service} Checking {$slapd}", 25); $pid = $unix->PIDOF($slapd); if ($unix->process_exists($pid)) { echo "slapd: [INFO] slapd PID:{$pid} still exists, kill it...\n"; unix_system_kill_force($pid); return; } restart_ldap_progress("{stopping_service} Checking {$slapd}", 28); exec("{$pgrep} -l -f {$slapd} 2>&1", $results); while (list($num, $line) = each($results)) { if (preg_match("#pgrep#", $line)) { continue; } if (preg_match("^([0-9]+)\\s+", $line, $re)) { echo "slapd: [INFO] slapd PID:{$re[1]} still exists, kill it\n"; unix_system_kill_force($re[1]); } } restart_ldap_progress("{stopping_service} {success}", 30); echo "slapd: [INFO] slapd stopped, success...\n"; }
function zarafa_server2_stop() { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/zarafa-server2-stop.pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: Task Already running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); $zarafaserver = $unix->find_program("zarafa-server"); if (!is_file($zarafaserver)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: zarafa-server (2) is not installed...\n"; } return; } $pid = ZARAFA_SERVER2_PID(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: zarafa-server (2) already stopped\n"; } return; } $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: zarafa-server (2) instance running since {$time}mn\n"; } $kill = $unix->find_program("kill"); unix_system_kill($pid); for ($i = 1; $i < 61; $i++) { sleep(1); $pid = ZARAFA_SERVER2_PID(); if ($unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: zarafa-server (2) waiting {$i}/60\n"; } } else { break; } } $pid = ZARAFA_SERVER2_PID(); if ($unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: zarafa-server (2) failed to stop pid:{$pid}\n"; } return; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: zarafa-server (2) success\n"; } }
function stop($aspid = false) { $unix = new unix(); if (!$aspid) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); } $sock = new sockets(); $EnableArticaFrontEndToNGninx = $sock->GET_INFO("EnableArticaFrontEndToNGninx"); $EnableArticaFrontEndToApache = $sock->GET_INFO("EnableArticaFrontEndToApache"); if (!is_numeric($EnableArticaFrontEndToNGninx)) { $EnableArticaFrontEndToNGninx = 0; } if (!is_numeric($EnableArticaFrontEndToApache)) { $EnableArticaFrontEndToApache = 0; } if ($EnableArticaFrontEndToApache == 1) { apache_stop(); } $GLOBALS["SERVICE_NAME"] = "Artica lighttpd service"; $pid = LIGHTTPD_PID(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} already stopped...\n"; } return; } $pid = LIGHTTPD_PID(); if ($GLOBALS["MONIT"]) { @file_put_contents("/var/run/artica-apache/apache.pid", $pid); @file_put_contents("/var/run/lighttpd/lighttpd.pid", $pid); return; } $nohup = $unix->find_program("nohup"); $php5 = $unix->LOCATE_PHP5_BIN(); $lighttpd_bin = $unix->find_program("lighttpd"); $kill = $unix->find_program("kill"); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Shutdown pid {$pid}...\n"; } unix_system_kill($pid); for ($i = 0; $i < 5; $i++) { $pid = LIGHTTPD_PID(); if (!$unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} waiting pid:{$pid} {$i}/5...\n"; } sleep(1); } $pid = LIGHTTPD_PID(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} success...\n"; } killallphpcgi(); return; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} shutdown - force - pid {$pid}...\n"; } unix_system_kill_force($pid); for ($i = 0; $i < 5; $i++) { $pid = LIGHTTPD_PID(); if (!$unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} waiting pid:{$pid} {$i}/5...\n"; } sleep(1); } if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} success...\n"; } killallphpcgi(); return; } else { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} failed...\n"; } } }
function stop($aspid = false) { if ($GLOBALS["MONIT"]) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} runned by Monit, abort\n"; } return; } $unix = new unix(); if (!$aspid) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Artica script already running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); } $pid = PID_NUM(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service already stopped...\n"; } return; } $pid = PID_NUM(); $nohup = $unix->find_program("nohup"); $php5 = $unix->LOCATE_PHP5_BIN(); $kill = $unix->find_program("kill"); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service Shutdown pid {$pid}...\n"; } build_progress("{stopping_service}", 6); squid_admin_mysql(1, "Stopping Categories Service", "nothing", __FILE__, __LINE__); unix_system_kill($pid); for ($i = 0; $i < 5; $i++) { $pid = PID_NUM(); if (!$unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service waiting pid:{$pid} {$i}/5...\n"; } sleep(1); } $pid = PID_NUM(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service success...\n"; } return; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service shutdown - force - pid {$pid}...\n"; } unix_system_kill_force($pid); for ($i = 0; $i < 5; $i++) { build_progress("{stopping_service} {$i}/5", 7); $pid = PID_NUM(); if (!$unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service waiting pid:{$pid} {$i}/5...\n"; } sleep(1); } if ($unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service failed...\n"; } return; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service success...\n"; } build_progress("{stopped}", 8); }
function Killing() { $unix = new unix(); $pid = PID_NUM(); $kill = $unix->find_program("kill"); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service success...\n"; } return; } unix_system_kill($pid); for ($i = 0; $i < 5; $i++) { $pid = PID_NUM(); if (!$unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service waiting pid:{$pid} {$i}/5...\n"; } sleep(1); } $pid = PID_NUM(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service success...\n"; } return; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service shutdown - force - pid {$pid}...\n"; } unix_system_kill_force($pid); }
function stop($aspid = false) { if ($GLOBALS["MONIT"]) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} runned by Monit, abort\n"; } return; } $unix = new unix(); if (!$aspid) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Artica script already running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); } $pid = PID_NUM(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service already stopped...\n"; } killbyports(); return; } $pid = PID_NUM(); $nohup = $unix->find_program("nohup"); $php5 = $unix->LOCATE_PHP5_BIN(); $kill = $unix->find_program("kill"); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} notify framework\n"; } shell_exec("{$php5} /usr/share/artica-postfix/exec.squidguard.php --notify-stop"); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service Shutdown pid {$pid}...\n"; } unix_system_kill($pid); for ($i = 0; $i < 5; $i++) { $pid = PID_NUM(); if (!$unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service waiting pid:{$pid} {$i}/5...\n"; } sleep(1); } $pid = PID_NUM(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service success...\n"; } killbyports(); @unlink("/var/log/squid/UFDB_SOCKET_ERROR"); return; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service shutdown - force - pid {$pid}...\n"; } unix_system_kill_force($pid); for ($i = 0; $i < 5; $i++) { $pid = PID_NUM(); if (!$unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service waiting pid:{$pid} {$i}/5...\n"; } sleep(1); } if ($unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service failed...\n"; } @unlink("/var/log/squid/UFDB_SOCKET_ERROR"); return; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service success...\n"; } killbyports(); @unlink("/var/log/squid/UFDB_SOCKET_ERROR"); }
function ucarp_stop_single($pid) { $unix = new unix(); $ucarp_bin = $unix->find_program("ucarp"); if (!is_file($ucarp_bin)) { echo "Starting......: " . date("H:i:s") . " UCARP Not installed...\n"; return; } $kill = $unix->find_program("kill"); $ifconfig = $unix->find_program("ifconfig"); if (!$unix->process_exists($pid)) { echo "Starting......: " . date("H:i:s") . " UCARP [{$pid}]: Not running...\n"; return; } $cmdline = var_export(@file_get_contents("/proc/{$pid}/cmdline"), true); if (preg_match("#'--interface=(.+?)'#", $cmdline, $re)) { echo "Starting......: " . date("H:i:s") . " UCARP: [{$pid}]: Shutting down interface ucarp:{$re[1]}...\n"; shell_exec("{$ifconfig} {$re[1]}:ucarp down"); } echo "Starting......: " . date("H:i:s") . " UCARP: [{$pid}]: Shutting down {$pid}...\n"; for ($i = 0; $i < 10; $i++) { unix_system_kill($pid); sleep(1); if (!$unix->process_exists($pid)) { break; } } if (!$unix->process_exists($pid)) { echo "Starting......: " . date("H:i:s") . " UCARP: [{$pid}]: Shutting down success...\n"; } }
function stop($aspid = false) { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; if (!$aspid) { $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: Already task running PID {$pid} since {$time}mn\n"; } return; } } @file_put_contents($pidfile, getmypid()); $pid = ZARAFA_SEARCH_PID(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} already stopped...\n"; } return; } if (is_file("/tmp/zarafa-upgrade-lock")) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} database upgrade is taking place.\n"; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: Do not stop this process bacause it may render your database unusable..\n"; } return; } $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Daemon with a ttl of {$time}mn\n"; } $kill = $unix->find_program("kill"); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} killing smoothly PID {$pid}...\n"; } unix_system_kill($pid); sleep(1); for ($i = 1; $i < 5; $i++) { $pid = ZARAFA_SEARCH_PID(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} pid {$pid} successfully stopped ...\n"; } break; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} wait pid {$pid} {$i}/5\n"; } sleep(1); } $pid = ZARAFA_SEARCH_PID(); if ($unix->process_exists($pid)) { unix_system_kill_force($pid); sleep(1); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} force killing {$pid}...\n"; } for ($i = 1; $i < 5; $i++) { $pid = ZARAFA_SEARCH_PID(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} pid {$pid} successfully stopped ...\n"; } break; } unix_system_kill_force($pid); sleep(1); } } if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} daemon success...\n"; } return; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} daemon failed...\n"; } }
function stop_squid($aspid = false) { if (function_exists("debug_backtrace")) { $trace = debug_backtrace(); if (isset($trace[1])) { $file = basename($trace[1]["file"]); $function = $trace[1]["function"]; $line = $trace[1]["line"]; $called = "Called by {$function}() from line {$line}"; } } $GLOBALS["LOGS"] = array(); $unix = new unix(); if (!$aspid) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . "Already `task` running PID {$pid} since {$time}mn\n"; } system_admin_events("stop_squid::Already task running PID {$pid} since {$time}mn", __FUNCTION__, __FILE__, __LINE__, "proxy"); return; } @file_put_contents($pidfile, getmypid()); } $sock = new sockets(); $MonitConfig = unserialize(base64_decode($sock->GET_INFO("SquidWatchdogMonitConfig"))); $MonitConfig = watchdog_config_default($MonitConfig); $STOP_SQUID_TIMEOUT = $MonitConfig["StopMaxTTL"]; $STOP_SQUID_MAXTTL_DAEMON = $MonitConfig["STOP_SQUID_MAXTTL_DAEMON"]; if (!is_numeric($STOP_SQUID_TIMEOUT)) { $STOP_SQUID_TIMEOUT = 60; } if (!is_numeric($STOP_SQUID_MAXTTL_DAEMON)) { $STOP_SQUID_MAXTTL_DAEMON = 5; } if ($STOP_SQUID_TIMEOUT < 5) { $STOP_SQUID_TIMEOUT = 5; } $squidbin = $unix->find_program("squid"); $kill = $unix->find_program("kill"); $pgrep = $unix->find_program("pgrep"); if (!is_file($squidbin)) { $squidbin = $unix->find_program("squid3"); } if (!is_file($squidbin)) { system_admin_events("Squid not seems to be installed", __FUNCTION__, __FILE__, __LINE__, "proxy"); return; } $suffix = " (by unknown process)"; if ($GLOBALS["MONIT"]) { $suffix = " (by system monitor)"; } if ($GLOBALS["CRASHED"]) { $suffix = " ( after a crash )"; } if ($GLOBALS["BY_CACHE_LOGS"]) { $suffix = " ( ordered by logs monitor )"; } if ($GLOBALS["BY_STATUS"]) { $suffix = " ( by Artica monitor )"; } if ($GLOBALS["BY_CLASS_UNIX"]) { $suffix = " (by Artica class.unix.inc)"; } if ($GLOBALS["BY_FRAMEWORK"]) { $suffix = " (by Artica framework)"; } if ($GLOBALS["BY_OTHER_SCRIPT"]) { $suffix = " (by other script)"; } if ($GLOBALS["BY_ARTICA_INSTALL"]) { $suffix = " (by artica-install)"; } if ($GLOBALS["BY_FORCE_RECONFIGURE"]) { $suffix = " (after building settings)"; } if ($GLOBALS["MONIT"]) { if (function_exists("debug_backtrace")) { $trace = debug_backtrace(); if (isset($trace[1])) { $file = basename($trace[1]["file"]); $function = $trace[1]["function"]; $line = $trace[1]["line"]; $called = "Called by {$function}() from line {$line}"; } } $pid = SQUID_PID(); if ($unix->process_exists($pid)) { $ps = $unix->find_program("ps"); $grep = $unix->find_program("grep"); exec("{$ps} aux|{$grep} squid 2>&1", $results); return; } squid_admin_mysql(2, "Monit ordered to stop squid", $called); } if ($GLOBALS["BY_ARTICA_INSTALL"]) { $pid = SQUID_PID(); if ($unix->process_exists($pid)) { $ps = $unix->find_program("ps"); $grep = $unix->find_program("grep"); exec("{$ps} aux|{$grep} squid 2>&1", $results); return; } squid_admin_mysql(2, "artica-install ordered to stop squid", $called); } $t1 = time(); $pid = SQUID_PID(); if (!$GLOBALS["FORCE"]) { if ($unix->process_exists($pid)) { $timeTTL = $unix->PROCCESS_TIME_MIN($pid); if ($timeTTL < $STOP_SQUID_MAXTTL_DAEMON) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . "Squid live since {$timeTTL}Mn, this is not intended to stop before {$STOP_SQUID_MAXTTL_DAEMON}Mn\n"; } Events("Squid live since {$timeTTL}Mn, this is not intended to stop before {$STOP_SQUID_MAXTTL_DAEMON}Mn"); if (function_exists("debug_backtrace")) { $trace = debug_backtrace(); if (isset($trace[1])) { $file = basename($trace[1]["file"]); $function = $trace[1]["function"]; $line = $trace[1]["line"]; $called = "Called by {$function}() from line {$line}"; } } reload_squid(true); return; } } } if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " Squid-Cache service Already stopped...\n"; } KillGhosts(); return; } $date = date("Y-m-d H:i:s"); $timeTTL = $unix->PROCCESS_TIME_MIN($pid); squid_admin_mysql(1, "Stopping Squid-Cache service: running since {$timeTTL}Mn {$suffix}", "{$suffix} - {$date}\nSquid live since {$timeTTL}Mn and a process ask to stop it\n{$called}", __FILE__, __LINE__); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " Squid-Cache service PID {$pid} running since {$timeTTL}Mn....\n"; } $commut = "shutdown"; if ($GLOBALS["KILL_ALL"]) { $commut = "kill"; } exec("{$squidbin} -f /etc/squid3/squid.conf -k {$commut} 2>&1", $shutdown); if (stop_squid_analyze($shutdown)) { $STOP_SQUID_TIMEOUT = 1; } if ($GLOBALS["FORCE"]) { $STOP_SQUID_TIMEOUT = 5; } if ($GLOBALS["KILL_ALL"]) { $STOP_SQUID_TIMEOUT = 2; } $PRC = 20; $MAXPRC = 30; $AB = 0; for ($i = 0; $i < $STOP_SQUID_TIMEOUT; $i++) { sleep(1); $PRC++; if ($PRC > $MAXPRC - 1) { $PRC = $MAXPRC - 1; } build_progress_restart("{stopping_service}", $PRC); $STOPIT = false; $task = null; $pid = SQUID_PID(); if (!$unix->process_exists($pid)) { break; } $cmdline = @file_get_contents("/proc/{$pid}/cmdline"); if (preg_match("#\\((.+?)\\)-#", $cmdline, $re)) { $task = $re[1]; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " Squid-Cache service waiting {$i} seconds (max {$STOP_SQUID_TIMEOUT}) for {$pid} PID Task:{$task}....\n"; } $shutdown = array(); if ($STOPIT) { break; } } $pid = SQUID_PID(); if ($unix->process_exists($pid)) { $STOP_SQUID_TIMEOUT = 10; exec("{$squidbin} -f /etc/squid3/squid.conf -k kill >/dev/null 2>&1"); if (stop_squid_analyze($shutdown)) { $STOP_SQUID_TIMEOUT = 1; } if ($GLOBALS["FORCE"]) { $STOP_SQUID_TIMEOUT = 5; } if ($GLOBALS["KILL_ALL"]) { $STOP_SQUID_TIMEOUT = 2; } for ($i = 0; $i < $STOP_SQUID_TIMEOUT; $i++) { if ($GLOBALS["OUTPUT"]) { echo "Killing.......: " . date("H:i:s") . " Squid-Cache service waiting {$i}/10 seconds for {$pid} PID Task:{$task}....\n"; } sleep(1); $pid = SQUID_PID(); if (!$unix->process_exists($pid)) { break; } } } $pidof = $unix->find_program("pidof"); $kill = $unix->find_program("kill"); if ($unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " Squid-Cache service PID(s): " . exec("{$pidof} {$squidbin} 2>&1") . "\n"; } } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " Squid-Cache service Search ghost processes...\n"; } $pids = explode(" ", exec("{$pidof} {$squidbin} 2>&1")); if ($GLOBALS["VERBOSE"]) { echo "exec({$pidof} {$squidbin} 2>&1) = `" . exec("{$pidof} {$squidbin} 2>&1") . "`"; } while (list($num, $pid) = each($pids)) { if (!is_numeric($pid)) { continue; } if ($pid < 10) { continue; } if (!$unix->process_exists($pid)) { continue; } $cmdline = trim(@file_get_contents("/proc/{$pid}/cmdline")); if (preg_match("#\\((.+?)\\)-#", $cmdline, $re)) { $task = $re[1]; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " Squid-Cache service Killing ghost task pid {$pid} `{$task}`\n"; } unix_system_kill($pid); if ($unix->process_exists($pid)) { for ($i = 0; $i < 4; $i++) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " Squid-Cache service waiting {$i} seconds (max 3) for {$pid} PID Task:{$task}....\n"; } if (!$unix->process_exists($pid)) { break; } sleep(1); } } if ($unix->process_exists($pid)) { unix_system_kill_force($pid); } } KillGhosts(); if (is_file("/dev/shm/squid-cache_mem.shm")) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " Squid-Cache service Removing /dev/shm/squid-cache_mem.shm\n"; } @unlink("/dev/shm/squid-cache_mem.shm"); } if (is_file("/dev/shm/squid-squid-page-pool.shm")) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " Squid-Cache service Removing /dev/shm/squid-squid-page-pool.shm\n"; } @unlink("/dev/shm/squid-squid-page-pool.shm"); } if (function_exists("debug_backtrace")) { $trace = debug_backtrace(); if (isset($trace[1])) { $sourcefunction = $trace[1]["function"]; $sourceline = $trace[1]["line"]; $executed = "Executed by {$sourcefunction}() line {$sourceline}\nusing argv:{$GLOBALS["ARGVS"]}\n"; } } system_admin_events("Squid success to stop\n" . @implode("\n", $GLOBALS["LOGS"]), __FUNCTION__, __FILE__, __LINE__, "proxy"); }
function stop($aspid = false) { $unix = new unix(); if (!$aspid) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); } $pid = PID_NUM(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service already stopped...\n"; } return; } $pid = PID_NUM(); $nohup = $unix->find_program("nohup"); $php5 = $unix->LOCATE_PHP5_BIN(); $kill = $unix->find_program("kill"); $chmod = $unix->find_program("chmod"); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service Shutdown pid {$pid}...\n"; } unix_system_kill($pid); for ($i = 0; $i < 5; $i++) { $pid = PID_NUM(); if (!$unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service waiting pid:{$pid} {$i}/5...\n"; } sleep(1); } $pid = PID_NUM(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service success...\n"; } return; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service shutdown - force - pid {$pid}...\n"; } unix_system_kill_force($pid); for ($i = 0; $i < 5; $i++) { $pid = PID_NUM(); if (!$unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service waiting pid:{$pid} {$i}/5...\n"; } sleep(1); } if ($unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service failed...\n"; } return; } }
function stop() { $unix = new unix(); echo "Stopping FreeRadius.............: find binaries daemons\n"; $pidof = $unix->find_program("pidof"); $kill = $unix->find_program("kill"); $pid = freeradius_pid(); if (!$unix->process_exists($pid)) { echo "Stopping FreeRadius.............: Already stopped\n"; return; } $pidtime = $unix->PROCCESS_TIME_MIN($pid); echo "Stopping FreeRadius.............: PID {$pid} since {$pidtime}mn\n"; unix_system_kill($pid); for ($i = 1; $i < 11; $i++) { echo "Stopping FreeRadius.............: waiting PID: {$pid} {$i}/10\n"; sleep(1); $pid = freeradius_pid(); if (!$unix->process_exists($pid)) { echo "Stopping FreeRadius.............: Stopped\n"; return; } } $pid = freeradius_pid(); if (!$unix->process_exists($pid)) { echo "Stopping FreeRadius.............: Stopped\n"; return; } else { echo "Stopping FreeRadius.............: Failed\n"; } }