Example #1
0
static void
monitoring_loop(service_info_t *si)
{
	long jiffies = 0;
	GTimer *timer;
	GError *error = NULL;
	guint proc_count;

	timer = g_timer_new();
	monitor_get_status(svc_mon, si);
	_add_custom_tags(si);

	proc_count = supervisor_children_startall(NULL, NULL);
	DEBUG("First started %u processes", proc_count);

	for (;;) { /* main loop */
		struct timeval tv_sleep;

		if (flag_restart_children) {
			if (auto_restart_children) {
				supervisor_children_repair(CHILD_KEY);
				supervisor_children_enable(CHILD_KEY, TRUE);
				proc_count = supervisor_children_startall(NULL,NULL);

				DEBUG("Started %u processes", proc_count);
				flag_restart_children = !!proc_count;
			} else {
				DEBUG("One of my children died, I will die too (auto_restart_children=%d)", auto_restart_children);
				break;
			}
		}

		if (!flag_running)
			break;

		if (g_timer_elapsed(timer, NULL) >= 1.0) {
			if (!((++jiffies) % monitor_period)) {
				monitor_get_status(svc_mon, si);
				_add_custom_tags(si);
			}
			if (!register_namespace_service(si, &error)) {
				ERROR("Failed to register the service: %s", gerror_get_message(error));
				g_clear_error(&error);
			}
			g_timer_reset(timer);
		}

		tv_sleep.tv_sec = 1L;
		tv_sleep.tv_usec = 0L;
		select(0, NULL, NULL, NULL, &tv_sleep);
		errno = 0;
	}

	supervisor_children_stopall(4);
	supervisor_children_catharsis(NULL, NULL);

	g_free(timer);
}
Example #2
0
static void
monitoring_loop(service_info_t *si)
{
	long jiffies = 0;
	GTimer *timer;
	GError *error = NULL;
	guint proc_count;

	timer = g_timer_new();
	monitor_get_status(svc_mon, si);
	_add_custom_tags(si);

	proc_count = supervisor_children_startall(NULL, NULL);
	GRID_DEBUG("First started %u processes", proc_count);

	while (flag_running) { /* main loop */

		if (flag_restart_children) {
			if (auto_restart_children) {
				supervisor_children_repair(CHILD_KEY);
				supervisor_children_enable(CHILD_KEY, TRUE);
				proc_count = supervisor_children_startall(NULL,NULL);

				GRID_DEBUG("Started %u processes", proc_count);
				flag_restart_children = !!proc_count;
			} else {
				GRID_DEBUG("One of my children died, I will die too (auto_restart_children=%d)", auto_restart_children);
				break;
			}
		}

		if (!flag_running)
			break;

		gdouble elapsed = g_timer_elapsed(timer, NULL);
		if (elapsed >= 1.0) {
			if (!((++jiffies) % monitor_period)) {
				monitor_get_status(svc_mon, si);
				_add_custom_tags(si);
			}
			if (!register_namespace_service(si, &error)) {
				GRID_WARN("Failed to register the service: %s", gerror_get_message(error));
				g_clear_error(&error);
			}
			g_timer_reset(timer);
			elapsed = 0.0;
		}

		g_usleep (1000000UL - ((gulong)elapsed));
	}

	supervisor_children_stopall(4);
	supervisor_children_catharsis(NULL, NULL);

	g_free(timer);
}
Example #3
0
static gboolean
_configure_registration(struct sqlx_service_s *ss)
{
	struct service_info_s *si = ss->si;

	si->tags = g_ptr_array_new();
	g_strlcpy(si->ns_name, ss->ns_name, sizeof(si->ns_name));
	g_strlcpy(si->type, ss->service_config->srvtype, sizeof(si->type));
	grid_string_to_addrinfo(ss->announce->str, &(si->addr));

	service_tag_set_value_string(
			service_info_ensure_tag(si->tags, "tag.type"),
			ss->service_config->srvtag);

	_add_custom_tags(si, ss->custom_tags);

	service_tag_set_value_string(
			service_info_ensure_tag(si->tags, "tag.vol"),
			ss->volume);

	return TRUE;
}