function restart($nopid = false) { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; if (!$nopid) { $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()); build_progress_reconfigure("{stopping_service} {webserver}", 50); apache_stop(true); build_progress_reconfigure("{reconfiguring} {webserver}", 60); apache_config(); build_progress_reconfigure("{starting_service} {webserver}", 80); apache_start(true); build_progress_reconfigure("{starting_service} {webserver} {done}", 85); build_progress_reconfigure2("{starting_service} {webserver} {done}", 100); }
function start($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; } } $sock = new sockets(); 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]: {$GLOBALS["SERVICE_NAME"]} Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); } if (!is_file("/etc/modprobe.d/blacklist-floppy.conf")) { @mkdir("/etc/modprobe.d", 0755, true); $rmmod = $unix->find_program("rmmod"); $update_initframs = $unix->find_program("update-initramfs"); @file_put_contents("/etc/modprobe.d/blacklist-floppy.conf", "blacklist floppy\n"); shell_exec("{$rmmod} floppy"); shell_exec("{$update_initframs} -u >/dev/null 2>&1 &"); } $EnableArticaFrontEndToNGninx = $sock->GET_INFO("EnableArticaFrontEndToNGninx"); $EnableArticaFrontEndToApache = $sock->GET_INFO("EnableArticaFrontEndToApache"); if (!is_numeric($EnableArticaFrontEndToNGninx)) { $EnableArticaFrontEndToNGninx = 0; } if (!is_numeric($EnableArticaFrontEndToApache)) { $EnableArticaFrontEndToApache = 0; } $EnableNginx = $sock->GET_INFO("EnableNginx"); $EnableFreeWeb = $sock->GET_INFO("EnableFreeWeb"); if (!is_numeric($EnableFreeWeb)) { $EnableFreeWeb = 0; } if (!is_numeric($EnableNginx)) { $EnableNginx = 1; } if ($EnableNginx == 0) { $EnableArticaFrontEndToNGninx = 0; } $unix->CleanOldLibs(); $chmod = $unix->find_program("chmod"); @mkdir("/etc/artica-postfix/settings/Daemons", 0755, true); shell_exec("{$chmod} -R 0755 /etc/artica-postfix/settings >/dev/null 2>&1"); $sock = new sockets(); $DisableForceFCK = intval($sock->GET_INFO("DisableForceFCK")); @unlink("/forcefsck"); if ($DisableForceFCK == 0) { @touch("/forcefsck"); } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} EnableArticaFrontEndToNGninx:{$EnableArticaFrontEndToNGninx}\n"; } $pid = LIGHTTPD_PID(); if ($EnableArticaFrontEndToNGninx == 1) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} transfered to Nginx..\n"; } if ($unix->process_exists($pid)) { ToSyslog("Stopping artica-webinterface service using lighttpd (transfered to Nginx)..."); stop(true); apache_stop(); } shell_exec("/etc/init.d/nginx start"); return; } if ($EnableArticaFrontEndToApache == 1) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Transfered to Apache..\n"; } if ($unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Stopping Lighttpd PID {$pid}\n"; } ToSyslog("Stopping artica-webinterface service using lighttpd (transfered to Apache)..."); stop(true); } $apachebin = $unix->LOCATE_APACHE_BIN_PATH(); if (is_file($apachebin)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Starting Apache Mode...\n"; } apache_start(); } return; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} transfered to lighttpd..\n"; } $GLOBALS["SERVICE_NAME"] = "Artica lighttpd service"; $pid = LIGHTTPD_PID(); if ($unix->process_exists($pid)) { $timepid = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} {$GLOBALS["SERVICE_NAME"]} already started {$pid} since {$timepid}Mn...\n"; } return; } ToSyslog("Starting artica-webinterface service using lighttpd..."); $nohup = $unix->find_program("nohup"); $php5 = $unix->LOCATE_PHP5_BIN(); $rm = $unix->find_program("rm"); $lighttpd_bin = $unix->find_program("lighttpd"); $LIGHTTPD_CONF_PATH = LIGHTTPD_CONF_PATH(); @mkdir("/var/run/lighttpd", 0755, true); @mkdir("/var/log/lighttpd", 0755, true); $cmd = "{$nohup} {$php5} /usr/share/artica-postfix/exec.web-community-filter.php --register-lic >/dev/null 2>&1 &"; if ($GLOBALS["VERBOSE"]) { echo "{$cmd}\n"; } shell_exec($cmd); buildConfig(); $cmd = "{$lighttpd_bin} -f {$LIGHTTPD_CONF_PATH}"; if ($GLOBALS["VERBOSE"]) { echo "{$cmd}\n"; } shell_exec($cmd); for ($i = 0; $i < 8; $i++) { $pid = LIGHTTPD_PID(); if ($unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} waiting {$i}/8...\n"; } sleep(1); } $pid = LIGHTTPD_PID(); if ($unix->process_exists($pid)) { ToSyslog("{$GLOBALS["SERVICE_NAME"]} Success service started pid:{$pid}"); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Success service started pid:{$pid}...\n"; } shell_exec("{$php5} /usr/share/artica-postfix/exec.apc.compile.php"); if (!is_file('/etc/init.d/artica-memcache')) { shell_exec("{$php5} /usr/share/artica-postfix/exec.initslapd.php --memcache"); } shell_exec("{$nohup} {$php5} /usr/share/artica-postfix/exec.initslapd.php --phppfm-restart-back >/dev/null 2>&1 &"); shell_exec("{$nohup} /etc/init.d/artica-memcached start >/dev/null 2>&1 &"); shell_exec("{$nohup} /etc/init.d/monit restart >/dev/null 2>&1 &"); $APACHE_SRC_ACCOUNT = $unix->APACHE_SRC_ACCOUNT(); $APACHE_SRC_GROUP = $unix->APACHE_SRC_GROUP(); $unix->chown_func($APACHE_SRC_ACCOUNT, $APACHE_SRC_GROUP, "/var/lib/php5/*"); } else { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} failed...\n"; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$cmd}\n"; } } }