Ejemplo n.º 1
0
int Sentinel::watch() {
    std::string pid_path,
                start_cmd;

    while (true) {
        for (auto it = config_.begin(); it != config_.end(); ++it) {
            pid_path = it->first;
            start_cmd = it->second;
            if (is_process_dead(pid_path)) {
                logging::error("Process under: " + pid_path + " not alive.");

                if (max_retries_ > DEFAULT_MAX_RETRIES &&
                        retry_attempts_[pid_path] >= max_retries_) {
                    logging::critical("Maximum process revival retries "
                                      "exceeded, aborting...");
                    return stop();
                }

                logging::info("Invoking: " + start_cmd);
                start_process(start_cmd, pid_path);
                retry_attempts_[pid_path]++;
            } else {
                // if the process is alive, reset it's retry attempts counter
                retry_attempts_[pid_path] = 0;
            }
        }
        keep_system_alive();
        sleep(check_interval_);
    }
}
Ejemplo n.º 2
0
oslProcessError SAL_CALL osl_joinProcessWithTimeout(oslProcess Process, const TimeValue* pTimeout)
{
	oslProcessImpl* pChild    = ChildList;
	oslProcessError osl_error = osl_Process_E_None;
		
    OSL_PRECOND(Process, "osl_joinProcess: Invalid parameter");
    OSL_ASSERT(ChildListMutex);
    
    if (NULL == Process || 0 == ChildListMutex)
        return osl_Process_E_Unknown;
            	 	
	osl_acquireMutex(ChildListMutex);
	
	/* check if process is a child of ours */
	while (pChild != NULL)
	{
		if (pChild == (oslProcessImpl*)Process)
			break;

		pChild = pChild->m_pnext;
	}

	osl_releaseMutex(ChildListMutex);
        
	if (pChild != NULL)
	{
		oslConditionResult cond_res = osl_waitCondition(pChild->m_terminated, pTimeout);
		
		if (osl_cond_result_timeout == cond_res)
		    osl_error = osl_Process_E_TimedOut;
		else if (osl_cond_result_ok != cond_res)
		    osl_error = osl_Process_E_Unknown;		    
	}
	else /* alien process; StatusThread will not be able
	   		to set the condition terminated */
	{
		pid_t pid = ((oslProcessImpl*)Process)->m_pid;
		
		if (pTimeout)
		{
			int timeout = 0;
			struct timeval tend;		
				
			gettimeofday(&tend, NULL);									
			
			tend.tv_sec += pTimeout->Seconds;			
												
			while (!is_process_dead(pid) && ((timeout = is_timeout(&tend)) == 0))
				sleep(1);
				
			if (timeout)
				osl_error = osl_Process_E_TimedOut;
		}
		else /* infinite */
		{
			while (!is_process_dead(pid))
				sleep(1);
		}				
	}
	return osl_error;	
}