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"; } } }
function start($aspid = false) { $unix = new unix(); $scriptlog = null; if ($GLOBALS["BYSCRIPT"]) { $scriptlog = " by init.d script"; } if (is_file("/etc/artica-postfix/FROM_ISO")) { if ($unix->file_time_min("/etc/artica-postfix/FROM_ISO") < 1) { return; } } 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(); @mkdir("/usr/share/artica-postfix/ressources/web", 0755, true); if (!is_dir("/usr/share/artica-postfix/ressources/web")) { echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service Warning !!! /usr/share/artica-postfix/ressources/web (permission denied !)\n"; } if ($unix->process_exists($pid)) { if (!$unix->is_socket("/usr/share/artica-postfix/ressources/web/framework.sock")) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service framework.sock no such socket, stop framework\n"; } stop(true); } else { $timepid = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Framework Service already started {$pid} since {$timepid}Mn...\n"; } return; } } $nohup = $unix->find_program("nohup"); $php5 = $unix->LOCATE_PHP5_BIN(); $lighttpd_bin = $unix->find_program("lighttpd"); if (!is_file($lighttpd_bin)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service lighttpd not found..\n"; } return; } @mkdir("/var/run/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 /etc/artica-postfix/framework.conf"; if ($GLOBALS["VERBOSE"]) { echo "{$cmd}\n"; } shell_exec($cmd); for ($i = 0; $i < 6; $i++) { $pid = LIGHTTPD_PID(); if ($unix->process_exists($pid)) { if (!$unix->is_socket("/usr/share/artica-postfix/ressources/web/framework.sock")) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service waiting framework.sock\n"; } } else { break; } } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service waiting {$i}/6...\n"; } sleep(1); } $pid = LIGHTTPD_PID(); if ($unix->process_exists($pid)) { FrmToSyslog("Success service started pid:{$pid}{$scriptlog}"); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service apply permissions on framework.sock\n"; } @chmod("/usr/share/artica-postfix/ressources/web/framework.sock", 0777); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service apply permissions on Settings direcotry\n"; } $unix->chmod_alldirs(0755, "/etc/artica-postfix/settings/Daemons/*"); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Framework Success service started pid:{$pid}...\n"; } } else { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service failed...\n"; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$cmd}\n"; } } }
function start($aspid = false) { $unix = new unix(); $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()); } $ROUNDCUBE_MAIN_FOLDER = ROUNDCUBE_MAIN_FOLDER(); if (!is_dir(ROUNDCUBE_MAIN_FOLDER())) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} not installed\n"; } return; } $RoundCubeHTTPEngineEnabled = intval($sock->GET_INFO("RoundCubeHTTPEngineEnabled")); $pid = LIGHTTPD_PID(); if ($RoundCubeHTTPEngineEnabled == 0) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} disabled (RoundCubeHTTPEngineEnabled)..\n"; } if ($unix->process_exists($pid)) { stop(true); } return; } 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; } $nohup = $unix->find_program("nohup"); $php5 = $unix->LOCATE_PHP5_BIN(); $apache2ctl = $unix->LOCATE_APACHE_CTL(); $LIGHTTPD_CONF_PATH = LIGHTTPD_CONF_PATH(); $RoundCubeHTTPSPort = intval($sock->GET_INFO("RoundCubeHTTPSPort")); $RoundCubeHTTPPort = intval($sock->GET_INFO("RoundCubeHTTPPort")); $RoundCubeUseSSL = intval($sock->GET_INFO("RoundCubeUseSSL")); if ($RoundCubeHTTPSPort == 0) { $RoundCubeHTTPSPort = 449; } if ($RoundCubeHTTPPort == 0) { $RoundCubeHTTPPort = 8888; } if (!is_file("/opt/artica/ssl/certs/lighttpd.pem")) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} creating SSL certificate..\n"; } exec("/usr/share/artica-postfix/bin/artica-install -lighttpd-cert 2>&1", $results); while (list($num, $line) = each($results)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} {$line}\n"; } } } apache_config(); if ($RoundCubeUseSSL == 1) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Get PID from PORT HTTPS/TCP:{$RoundCubeHTTPSPort}\n"; } $pids = $unix->PIDOF_BY_PORT($RoundCubeHTTPSPort); if (count($pids) > 0) { while (list($pid, $line) = each($pids)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} kill PID {$pid} that listens {$RoundCubeHTTPSPort}\n"; } $unix->KILL_PROCESS($pid, 9); } } } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Get PID from PORT HTTP/TCP:{$RoundCubeHTTPPort}\n"; } $pids = $unix->PIDOF_BY_PORT($RoundCubeHTTPPort); if (count($pids) > 0) { while (list($pid, $line) = each($pids)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} kill PID {$pid} that listens {$RoundCubeHTTPPort}\n"; } $unix->KILL_PROCESS($pid, 9); } } $cmd = "{$apache2ctl} -f {$LIGHTTPD_CONF_PATH} -k start"; if ($GLOBALS["VERBOSE"]) { echo "{$cmd}\n"; } shell_exec($cmd); for ($i = 0; $i < 6; $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}/6...\n"; } sleep(1); } $pid = LIGHTTPD_PID(); if ($unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Success service started pid:{$pid}...\n"; } } 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"; } } }
function status() { $unix = new unix(); $phpcgi = $unix->LIGHTTPD_PHP5_CGI_BIN_PATH(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pidtime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; $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; } if (!$GLOBALS["VERBOSE"]) { $timeExec = $unix->file_time_min($pidtime); if ($timeExec < 15) { return; } } @unlink($pidtime); @file_put_contents($pidtime, time()); @file_put_contents($pidfile, getmypid()); $pid = LIGHTTPD_PID(); $unix = new unix(); if ($unix->process_exists($pid)) { $timepid = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service running {$pid} since {$timepid}Mn...\n"; } } else { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service stopped...\n"; } start(); return; } $MAIN_PID = $pid; $phpcgi = $unix->LIGHTTPD_PHP5_CGI_BIN_PATH(); $kill = $unix->find_program("kill"); $array = $unix->PIDOF_PATTERN_ALL($phpcgi); if (count($array) == 0) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: no php-cgi processes...\n"; } return; } while (list($pid, $line) = each($array)) { $username = $unix->PROCESS_GET_USER($pid); if ($username == null) { continue; } if ($username != "root") { continue; } $time = $unix->PROCCESS_TIME_MIN($pid); $arrayPIDS[$pid] = $time; $ppid = $unix->PPID_OF($pid); if ($time > 20) { if ($ppid != $MAIN_PID) { if ($GLOBALS["VERBOSE"]) { echo "killing {$pid} {$time}mn ppid:{$ppid}/{$MAIN_PID}\n"; } unix_system_kill_force($pid); } } } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: " . count($arrayPIDS) . " php-cgi processes...\n"; } }