die; } if ($argv[1] == "--restart") { $GLOBALS["OUTPUT"] = true; restart(); die; } if ($argv[1] == "--reload") { $GLOBALS["OUTPUT"] = true; restart(); die; } if ($argv[1] == "--build") { $GLOBALS["OUTPUT"] = true; pamd_conf(); vsftpd_conf(); } function restart() { $unix = new unix(); $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["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); stop(true);
function start($aspid = false) { $unix = new unix(); $sock = new sockets(); $Masterbin = $unix->find_program("vsftpd"); if (!is_file($Masterbin)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, arpd not installed\n"; } 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]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); } $pid = PID_NUM(); if ($unix->process_exists($pid)) { $timepid = $unix->PROCCESS_TIME_MIN($pid); $vsftpd_version = vsftpd_version(); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} version {$vsftpd_version} already started {$pid} since {$timepid}Mn...\n"; } return; } $EnableDaemon = intval($sock->GET_INFO("EnableVSFTPDDaemon")); if ($EnableDaemon == 0) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service disabled (see EnableVSFTPDDaemon)\n"; } return; } $php5 = $unix->LOCATE_PHP5_BIN(); $sysctl = $unix->find_program("sysctl"); $echo = $unix->find_program("echo"); $nohup = $unix->find_program("nohup"); pamd_conf(); vsftpd_conf(); $cmd = "{$nohup} {$Masterbin} -olisten=YES /etc/vsftpd.conf >/dev/null 2>&1 &"; if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service\n"; } shell_exec($cmd); for ($i = 1; $i < 5; $i++) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} waiting {$i}/5\n"; } sleep(1); $pid = PID_NUM(); if ($unix->process_exists($pid)) { break; } } $pid = PID_NUM(); if ($unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Success PID {$pid}\n"; } } else { vsftpd_admin_mysql(0, "Starting VSFTPD service failed", null, __FILE__, __LINE__); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Failed\n"; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} {$cmd}\n"; } } }