Beispiel #1
0
pid_t
wd_main(int fork_wait_time)
{
	int i;

	if (!pool_config->use_watchdog)
		return 0;

	/* check pool_config data */
	wd_check_config();

	/* initialize */
	wd_init();

	wd_ppid = getpid();

	/* launch child process */
	child_pid = wd_child(1);

	if (!strcmp(pool_config->wd_lifecheck_method, MODE_HEARTBEAT))
	{
		for (i = 0; i < pool_config->num_hb_if; i++)
		{
			/* heartbeat receiver process */
			hb_receiver_pid[i] = wd_hb_receiver(1, &(pool_config->hb_if[i]));

			/* heartbeat sender process */
			hb_sender_pid[i] = wd_hb_sender(1, &(pool_config->hb_if[i]));
		}
	}

	/* fork lifecheck process*/
	lifecheck_pid = fork_a_lifecheck(fork_wait_time);

	return lifecheck_pid;
}
Beispiel #2
0
int
wd_reaper_watchdog(pid_t pid, int status)
{
	int i;

	/* watchdog lifecheck process exits */
	if (pid == lifecheck_pid)
	{
		if (WIFSIGNALED(status))
			pool_debug("watchdog lifecheck process %d exits with status %d by signal %d",
			           pid, status, WTERMSIG(status));
		else
			pool_debug("watchdog lifecheck process %d exits with status %d", pid, status);

		lifecheck_pid = fork_a_lifecheck(1);

		if (lifecheck_pid < 0)
		{
			pool_error("wd_reaper: fork a watchdog lifecheck process failed");
			return 0;
		}

		pool_log("fork a new watchdog lifecheck pid %d", lifecheck_pid);
	}

	/* watchdog child process exits */
	else if (pid == child_pid)
	{
		if (WIFSIGNALED(status))
			pool_debug("watchdog child process %d exits with status %d by signal %d",
			           pid, status, WTERMSIG(status));
		else
			pool_debug("watchdog child process %d exits with status %d", pid, status);

		child_pid = wd_child(1);

		if (child_pid < 0)
		{
			pool_error("wd_reaper: fork a watchdog child process failed");
			return 0;
		}

		pool_log("fork a new watchdog child pid %d", child_pid);
	}

	/* receiver/sender process exits */
	else
	{
		for (i = 0; i < pool_config->num_hb_if; i++)
		{
			if (pid == hb_receiver_pid[i])
			{
				if (WIFSIGNALED(status))
					pool_debug("watchdog heartbeat receiver process %d exits with status %d by signal %d",
					           pid, status, WTERMSIG(status));
				else
					pool_debug("watchdog heartbeat receiver process %d exits with status %d", pid, status);

				hb_receiver_pid[i] = wd_hb_receiver(1, pool_config->hb_if[i]);

				if (hb_receiver_pid[i] < 0)
				{
					pool_error("wd_reaper: fork a watchdog heartbeat receiver process failed");
					return 0;
				}
		
				pool_log("fork a new watchdog heartbeat receiver: pid %d", hb_receiver_pid[i]);
				break;
			}

			else if (pid == hb_sender_pid[i])
			{
				if (WIFSIGNALED(status))
					pool_debug("watchdog heartbeat sender process %d exits with status %d by signal %d",
					           pid, status, WTERMSIG(status));
				else
					pool_debug("watchdog heartbeat sender process %d exits with status %d", pid, status);

				hb_sender_pid[i] = wd_hb_sender(1, pool_config->hb_if[i]);

				if (hb_sender_pid[i] < 0)
				{
					pool_error("wd_reaper: fork a watchdog heartbeat sender process failed");
					return 0;
				}
		
				pool_log("fork a new watchdog heartbeat sender: pid %d", hb_sender_pid[i]);
				break;
			}
		}
	}
	
	return 1;
}
Beispiel #3
0
pid_t
wd_main(int fork_wait_time)
{
	int status = WD_INIT;
	int i;

	if (!pool_config->use_watchdog)
	{
		return 0;
	}

	/* check pool_config data */
	status = wd_check_config();
	if (status != WD_OK)
	{
		pool_error("watchdog: wd_check_config failed");
		return 0;
	}

	/* initialize */
	status = wd_init();
	if (status != WD_OK)
	{
		pool_error("watchdog: wd_init failed");
		return 0;
	}

	wd_ppid = getpid();

	/* launch child process */
	child_pid = wd_child(1);
	if (child_pid < 0 )
	{
		pool_error("launch wd_child failed");
		return 0;
	}

	if (!strcmp(pool_config->wd_lifecheck_method, MODE_HEARTBEAT))
	{
		for (i = 0; i < pool_config->num_hb_if; i++)
		{
			/* heartbeat receiver process */
			hb_receiver_pid[i] = wd_hb_receiver(1, pool_config->hb_if[i]);
			if (hb_receiver_pid[i] < 0 )
			{
				pool_error("launch wd_hb_receiver failed");
				return hb_receiver_pid[i];
			}

			/* heartbeat sender process */
			hb_sender_pid[i] = wd_hb_sender(1, pool_config->hb_if[i]);
			if (hb_sender_pid[i] < 0 )
			{
				pool_error("launch wd_hb_sender failed");
				return hb_sender_pid[i];
			}
		}
	}

	/* fork lifecheck process*/
	lifecheck_pid = fork_a_lifecheck(fork_wait_time);
	if (lifecheck_pid < 0 )
	{
		pool_error("launch lifecheck process failed");
		return 0;
	}

	return lifecheck_pid;
}
Beispiel #4
0
/* restart watchdog process specified by pid */
int
wd_reaper_watchdog(pid_t pid, int status)
{
	int i;

	/* watchdog lifecheck process exits */
	if (pid == lifecheck_pid)
	{
		if (WIFSIGNALED(status))
			ereport(DEBUG1,
					(errmsg("watchdog lifecheck process with PID:%d exits with status %d by signal %d",
							pid, status, WTERMSIG(status))));
		else
			ereport(DEBUG1,
					(errmsg("watchdog lifecheck process with PID:%d exits with status %d", pid, status)));

		lifecheck_pid = fork_a_lifecheck(1);

		ereport(LOG,
				(errmsg("fork a new watchdog lifecheck pid %d", lifecheck_pid)));

	}

	/* watchdog child process exits */
	else if (pid == child_pid)
	{
		if (WIFSIGNALED(status))
			ereport(DEBUG1,
					(errmsg("watchdog child process with PID:%d exits with status %d by signal %d",
							pid, status,WTERMSIG(status))));
		else
			ereport(DEBUG1,
				(errmsg("watchdog child process with PID:%d exits with status %d",
						pid, status)));


		child_pid = wd_child(1);

		ereport(LOG,
				(errmsg("fork a new watchdog child pid %d", child_pid)));

	}

	/* receiver/sender process exits */
	else
	{
		for (i = 0; i < pool_config->num_hb_if; i++)
		{
			if (pid == hb_receiver_pid[i])
			{
				if (WIFSIGNALED(status))
					ereport(DEBUG1,
							(errmsg("watchdog heartbeat receiver process with PID:%d exits with status %d by signal %d",
									pid, status, WTERMSIG(status))));
				else
					ereport(DEBUG1,
							(errmsg("watchdog heartbeat receiver process with PID:%d exits with status %d", pid, status)));

				hb_receiver_pid[i] = wd_hb_receiver(1, &(pool_config->hb_if[i]));

				ereport(LOG,
						(errmsg("fork a new watchdog heartbeat receiver with pid %d", hb_receiver_pid[i])));

				break;
			}

			else if (pid == hb_sender_pid[i])
			{
				if (WIFSIGNALED(status))
					ereport(DEBUG1,
							(errmsg("watchdog heartbeat sender process with PID:%d exits with status %d by signal %d",
									pid, status, WTERMSIG(status))));
				else
					ereport(DEBUG1,
							(errmsg("watchdog heartbeat sender process with PID:%d exits with status %d", pid, status)));

				hb_sender_pid[i] = wd_hb_sender(1, &(pool_config->hb_if[i]));

				ereport(LOG,
						(errmsg("fork a new watchdog heartbeat sender with PID:%d", hb_sender_pid[i])));
				break;
			}
		}
	}
	
	return 1;
}