// grab the PID from the file & check it's running (returns -1 on failure) // (also checks process names if file method fails, but this is unimplemented) pid_t getpid(std::string pidfile) { pid_t p = getpidfromfile(pidfile); if (p > 1) { if (confirmname(p)) { // is that pid really DG and running? return p; // it is so return it } } pid_t t = getpidfromcommand("e2guardian"); // pid file method failed // so try a search from the // command return t; // if it failed t will be -1 }
static SaAisErrorT service_start(void) { SaAisErrorT rc; int status; status = exec_command(start_script); if (status == 0) { rc = saAmfHealthcheckStart(my_amf_hdl, &my_comp_name, &my_healthcheck_key, SA_AMF_HEALTHCHECK_AMF_INVOKED, SA_AMF_COMPONENT_RESTART); if (rc != SA_AIS_OK) { syslog(LOG_ERR, "service_start: saAmfHealthcheckStart FAILED (%u)", rc); return SA_AIS_ERR_FAILED_OPERATION; } if (pidfile) { SaAmfRecommendedRecoveryT recrec = SA_AMF_NO_RECOMMENDATION; SaInt32T descendentsTreeDepth = 0; SaAmfPmErrorsT pmErr = SA_AMF_PM_ZERO_EXIT | SA_AMF_PM_NON_ZERO_EXIT; pid = getpidfromfile(pidfile, true); syslog(LOG_INFO, "Starting supervision of PID %u", pid); rc = saAmfPmStart(my_amf_hdl, &my_comp_name, pid, descendentsTreeDepth, pmErr, recrec); if (SA_AIS_OK != rc) { syslog(LOG_ERR, "service_start: saAmfPmStart FAILED (%u)", rc); return SA_AIS_ERR_FAILED_OPERATION; } } } if (status == 0) return SA_AIS_OK; else return SA_AIS_ERR_FAILED_OPERATION; }