function restart_ldap() { $unix = new unix(); $MYPID_FILE = "/etc/artica-postfix/pids/restart_ldap.pid"; $pid = $unix->get_pid_from_file($MYPID_FILE); if ($unix->process_exists($pid, basename(__FILE__))) { restart_ldap_progress("{failed}", 110); echo "slapd: [INFO] Artica task already running pid {$pid}\n"; die; } if (!$GLOBALS["FORCE"]) { $lastexecution = $unix->file_time_min($MYPID_FILE); if ($lastexecution == 0) { $unix->ToSyslog("Restarting the OpenLDAP by `{$GLOBALS["BY_FRAMEWORK"]}` aborted this command must be executed minimal each 1mn", false, basename(__FILE__)); echo "slapd: [INFO] this command must be executed minimal each 1mn\n"; die; } } @unlink($MYPID_FILE); @file_put_contents($MYPID_FILE, getmypid()); $unix->ToSyslog("Restarting the OpenLDAP daemon by `{$GLOBALS["BY_FRAMEWORK"]}`", false, basename(__FILE__)); restart_ldap_progress("{stopping_service}", 10); stop_ldap(true); restart_ldap_progress("{starting_service}", 40); start_ldap(true); }
function restart_ldap() { $unix = new unix(); $MYPID_FILE = "/etc/artica-postfix/pids/restart_ldap.pid"; $pid = $unix->get_pid_from_file($MYPID_FILE); if (!is_file("/etc/artica-postfix/settings/Daemons/EnableOpenLDAP")) { @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableOpenLDAP", 1); @chmod("/etc/artica-postfix/settings/Daemons/EnableOpenLDAP", 0755); } $EnableOpenLDAP = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableOpenLDAP")); if ($unix->process_exists($pid, basename(__FILE__))) { echo "slapd: [INFO] Artica task already running pid {$pid}\n"; restart_ldap_progress("{failed} [" . __LINE__ . "]", 110); die; } $pids = $unix->PIDOF_PATTERN_ALL(basename(__FILE__) . ".*?--restart", true); if (count($pids) > 0) { while (list($i, $line) = each($pids)) { echo "slapd: [INFO] Artica task already executed PID:{$i}... aborting\n"; } restart_ldap_progress("{failed}", 110); die; } if ($GLOBALS["MONIT"]) { squid_admin_mysql(0, "Monit (Watchdog) Ask to restart OpenLDAP service...", null, __FILE__, __LINE__); system_admin_mysql(0, "Monit (Watchdog) Ask to restart OpenLDAP service...", null, __FILE__, __LINE__); } if (!$GLOBALS["FORCE"]) { $lastexecution = $unix->file_time_min($MYPID_FILE); if ($lastexecution == 0) { $unix->ToSyslog("Restarting the OpenLDAP by `{$GLOBALS["BY_FRAMEWORK"]}` aborted this command must be executed minimal each 1mn", false, basename(__FILE__)); echo "slapd: [INFO] this command must be executed minimal each 1mn\n"; die; } } @unlink($MYPID_FILE); restart_ldap_progress("{build_init_script}", 5); $INITD_PATH = $unix->SLAPD_INITD_PATH(); echo "Script: {$INITD_PATH}\n"; buildscript(); if (!is_file($INITD_PATH)) { restart_ldap_progress("{build_init_script} {failed}", 110); return; } @file_put_contents($MYPID_FILE, getmypid()); $unix->ToSyslog("Restarting the OpenLDAP daemon by `{$GLOBALS["BY_FRAMEWORK"]}`", false, basename(__FILE__)); restart_ldap_progress("{stopping_service}", 10); stop_ldap(true); if ($EnableOpenLDAP == 1) { $php = $unix->LOCATE_PHP5_BIN(); shell_exec("/etc/init.d/monit restart"); restart_ldap_progress("{starting_service}", 40); start_ldap(true); } }