Example #1
0
int main(int argc, char **argv) {
	if(parse_args(argc, argv))
		return 0;
	int err = 0;
	printf("Starting Server %s (%s)...%ld\n", version_string, compiling_date, nowtime());
	if(myconfig_init(argc, argv) < 0) {
		printf("myconfig_init fail %m\n");
		goto error;
	}
	daemon_start(argc, argv);
	umask(0);
	ICALL(start_watchdog);
	ICALL(init_log);
	ICALL(init_glog);
	ICALL(init_fdinfo);
	ICALL(delay_task_init);
	ICALL(init_thread);
	ICALL(init_global);
	ICALL(vfs_init);
	ICALL(init_task_info);

	if (g_config.voss_flag == 0)
	{
		t_thread_arg arg;
		memset(&arg, 0, sizeof(arg));
		snprintf(arg.name, sizeof(arg.name), "./ott_server.so");
		LOG(glogfd, LOG_NORMAL, "prepare start %s\n", arg.name);
		arg.port = 80;
		arg.maxevent = myconfig_get_intval("vfs_sig_maxevent", 4096);
		if (init_vfs_thread(&arg))
			goto error;
		t_thread_arg arg1;
		memset(&arg1, 0, sizeof(arg1));
		snprintf(arg1.name, sizeof(arg1.name), "./ott_client.so");
		LOG(glogfd, LOG_NORMAL, "prepare start %s\n", arg1.name);
		arg1.maxevent = myconfig_get_intval("vfs_data_maxevent", 4096);
		if (init_vfs_thread(&arg1))
			goto error;
		ICALL(init_vfs_agent);
	}
	else
	{
		t_thread_arg arg;
		memset(&arg, 0, sizeof(arg));
		snprintf(arg.name, sizeof(arg.name), "./ott_voss.so");
		LOG(glogfd, LOG_NORMAL, "prepare start %s\n", arg.name);
		arg.port = g_config.sig_port;
		arg.maxevent = myconfig_get_intval("vfs_sig_maxevent", 4096);
		if (init_vfs_thread(&arg))
			goto error;
	}
	thread_jumbo_title();
	struct threadstat *thst = get_threadstat();
	if(start_threads() < 0)
		goto out;
	thread_reached(thst);
	gen_pidfile();	
	printf("Server Started\n");
	vfs_start_time = time(NULL);
	main_loop(thst);
out:
	printf("Stopping Server %s (%s)...\n", version_string, compiling_date);
	thread_reached(thst);
	stop_threads();
	myconfig_cleanup();
	fini_fdinfo();
	printf("Server Stopped.\n");
	return restart;
error:
	if(err == -ENOMEM) 
		printf("\n\033[31m\033[1mNO ENOUGH MEMORY\033[0m\n");

	printf("\033[31m\033[1mStart Fail.\033[0m\n");
	return -1;
}
Example #2
0
int main(int argc, char **argv) {
	if(parse_args(argc, argv))
		return 0;
	int err = 0;
	printf("Starting Server %s (%s)...%ld\n", version_string, compiling_date, nowtime());
	if(myconfig_init(argc, argv) < 0) {
		printf("myconfig_init fail %m\n");
		goto error;
	}
	daemon_start(argc, argv);
	umask(0);
	ICALL(init_log);
	ICALL(init_glog);
	ICALL(init_fdinfo);
	ICALL(delay_task_init);
	ICALL(init_thread);
	ICALL(init_global);
	ICALL(vfs_init);
	ICALL(init_task_info);
	ICALL(init_file_filter);
	ICALL(init_tc);
	if (get_self_info(&self_ipinfo))
	{
		LOG(glogfd, LOG_NORMAL, "get_self_role ERR!\n");
		self_ipinfo.role = ROLE_FCS;
	}
	if (self_ipinfo.role <= UNKOWN || self_ipinfo.role >= SELF_IP)
	{
		LOG(glogfd, LOG_ERROR, "get_self_role ERR!\n");
		fprintf(stderr, "get_self_role ERR!\n");
		goto error;
	}
	if (self_ipinfo.role != ROLE_VOSS_MASTER)
		ICALL(init_vfs_agent);
	char *srole = iprole[self_ipinfo.role];
	LOG(glogfd, LOG_NORMAL, "MY ROLE is %s\n", srole);

	t_thread_arg arg;
	memset(&arg, 0, sizeof(arg));
	snprintf(arg.name, sizeof(arg.name), "./%s_client.so", srole);
	LOG(glogfd, LOG_NORMAL, "prepare start %s\n", arg.name);
	if (ROLE_FCS != self_ipinfo.role)
	{
		arg.port = g_config.sig_port;
		arg.flag = 1;
	}
	arg.maxevent = myconfig_get_intval("vfs_sig_maxevent", 4096);
	if (init_vfs_thread(&arg))
		goto error;
	t_thread_arg arg1;
	memset(&arg1, 0, sizeof(arg1));
	snprintf(arg1.name, sizeof(arg1.name), "./%s_http.so", srole);
	LOG(glogfd, LOG_NORMAL, "prepare start %s\n", arg1.name);
	arg1.maxevent = myconfig_get_intval("vfs_data_maxevent", 4096);
	if (init_vfs_thread(&arg1))
		goto error;
	thread_jumbo_title();
	struct threadstat *thst = get_threadstat();
	if(start_threads() < 0)
		goto out;
	thread_reached(thst);
	gen_pidfile();	
	printf("Server Started\n");
	vfs_start_time = time(NULL);
	main_loop(thst);
out:
	printf("Stopping Server %s (%s)...\n", version_string, compiling_date);
	thread_reached(thst);
	stop_threads();
	myconfig_cleanup();
	fini_fdinfo();
	printf("Server Stopped.\n");
	return restart;
error:
	if(err == -ENOMEM) 
		printf("\n\033[31m\033[1mNO ENOUGH MEMORY\033[0m\n");
	
	printf("\033[31m\033[1mStart Fail.\033[0m\n");
	return -1;
}
Example #3
0
int main(int argc, char **argv)
{
	if (argc > 1)
	{
		if (strcasecmp(argv[1], "-v") == 0)
		{
			fprintf(stdout, "compile time [%s %s]\n", __DATE__, __TIME__);
			return -1;
		}
	}

	if (myconfig_init(argc, argv))
	{
		fprintf(stderr, "myconfig_init error [%s]\n", strerror(errno));
		return -1;
	}

	EnterDaemonMode();
	t_path_info path;
	memset(&path, 0, sizeof(path));

	if (init_para(&path))
		return -1;

	int ret = init_shm(&path);
	if (ret < 0)
	{
		LOG(fplog, LOG_ERROR, "init_shm err %m\n");
		report_2_nm(CDC_SHM_INIT_ERR, ID, LN);
		return -1;
	}

	LOG(fplog, LOG_NORMAL, "cdc start ok!\n");
	if (ret == 0 )
	{
		if (cdc_sub(&path, CDC_PLUS))
		{
			LOG(fplog, LOG_ERROR, "init_plus err %m\n");
			report_2_nm(CDC_NORMAL_ERR, ID, LN);
			return -1;
		}
	}
	LOG(fplog, LOG_NORMAL, "plus dir process ok!\n");

	time_t cur = time(NULL);
	time_t last = 0;
	int shm_sync_time = myconfig_get_intval("shm_synctime", 3600);

	while (1)
	{
		cdc_sub(&path, CDC_REALTIME);
		cur = time(NULL);
		if (cur - last >= shm_sync_time)
		{
			last = cur;
			do_sync_2_disk(&path);
		}
		sleep(10);
	}

	logclose(fplog);
	return 0;
}