Пример #1
0
void masterconn_reload(void) {
    masterconn *eptr = masterconnsingleton;
    uint32_t ReconnectionDelay;
    uint32_t MetaDLFreq;

    free(MasterHost);
    free(MasterPort);
    free(BindHost);

    MasterHost = cfg_getstr("MASTER_HOST","mfsmaster");
    MasterPort = cfg_getstr("MASTER_PORT","9419");
    BindHost = cfg_getstr("BIND_HOST","*");

    eptr->masteraddrvalid = 0;
    if (eptr->mode!=FREE) {
        eptr->mode = KILL;
    }

    Timeout = cfg_getuint32("MASTER_TIMEOUT",60);
    BackLogsNumber = cfg_getuint32("BACK_LOGS",50);
    BackMetaCopies = cfg_getuint32("BACK_META_KEEP_PREVIOUS",3);

    ReconnectionDelay = cfg_getuint32("MASTER_RECONNECTION_DELAY",5);
    MetaDLFreq = cfg_getuint32("META_DOWNLOAD_FREQ",24);

    if (Timeout>65536) {
        Timeout=65535;
    }
    if (Timeout<10) {
        Timeout=10;
    }
    if (BackLogsNumber<5) {
        BackLogsNumber=5;
    }
    if (BackLogsNumber>10000) {
        BackLogsNumber=10000;
    }
    if (MetaDLFreq>(BackLogsNumber/2)) {
        MetaDLFreq=BackLogsNumber/2;
    }
    if (BackMetaCopies>99) {
        BackMetaCopies=99;
    }

    main_timechange(reconnect_hook,TIMEMODE_RUN_LATE,ReconnectionDelay,0);
    main_timechange(download_hook,TIMEMODE_RUN_LATE,MetaDLFreq*3600,630);
}
Пример #2
0
            int masterconn_init(void) {
                uint32_t ReconnectionDelay;
                masterconn *eptr;

                ReconnectionDelay = cfg_getuint32("MASTER_RECONNECTION_DELAY",5);
                MasterHost = cfg_getstr("MASTER_HOST","mfsmaster");
                MasterPort = cfg_getstr("MASTER_PORT","9419");
                BindHost = cfg_getstr("BIND_HOST","*");
                Timeout = cfg_getuint32("MASTER_TIMEOUT",10);
                BackLogsNumber = cfg_getuint32("BACK_LOGS",50);
                BackMetaCopies = cfg_getuint32("BACK_META_KEEP_PREVIOUS",3);

                if (Timeout>65536) {
                    Timeout=65535;
                }
                if (Timeout<10) {
                    Timeout=10;
                }
                if (BackLogsNumber<5) {
                    BackLogsNumber=5;
                }
                if (BackLogsNumber>10000) {
                    BackLogsNumber=10000;
                }
                eptr = masterconnsingleton = malloc(sizeof(masterconn));
                passert(eptr);

                eptr->masteraddrvalid = 0;
                eptr->mode = FREE;
                eptr->pdescpos = -1;
                eptr->metafd = -1;
                eptr->oldmode = 0;

                currentlogversion = fs_getversion();
                if (!fs_ismastermode() && masterconn_initconnect(eptr)<0) {
                    return -1;
                }
                reconnect_hook = main_timeregister(TIMEMODE_RUN_LATE,ReconnectionDelay,0,masterconn_reconnect);
                main_destructregister(masterconn_term);
                main_pollregister(masterconn_desc,masterconn_serve);
                main_reloadregister(masterconn_reload);
                main_timeregister(TIMEMODE_RUN_LATE,60,0,masterconn_sessionsdownloadinit);
                return 0;
            }
Пример #3
0
int job_init(void) {
//	globalpool = (jobpool*)malloc(sizeof(jobpool));
	exiting = 0;
	globalpool = job_pool_new(cfg_getuint32("WORKERS_QUEUE_LENGTH",250)); // deprecated option

	job_reload();

	main_destruct_register(job_term);
	main_wantexit_register(job_wantexit);
	main_canexit_register(job_canexit);
	main_reload_register(job_reload);
	main_eachloop_register(job_heavyload_test);
	main_poll_register(job_desc,job_serve);
	return 0;
}
Пример #4
0
int state_init()
{
    int whethermaster = cfg_getuint32("MASTER_STATE", 1);
    g_virtual_ip = cfg_getstr("VIRTUAL_IP", "");
    int havevip  = checkvirtualip();

    if( ( whethermaster && !havevip ) || ( !whethermaster && havevip ) )  {
        MFSLOG(LOG_ERR, "state : %d  and havevip :%d  conflict vip:%s\n",
               whethermaster, havevip, g_virtual_ip);
        return -1;
    }

    whethermaster ? set_state(MFS_STATE_MASTER) : set_state(MFS_STATE_SLAVE);

    main_timeregister(TIMEMODE_RUNALL, 2, 0,  state_refresh);

    return 0;
}
Пример #5
0
int matoslaserv_init() {
	ListenHost = cfg_getstr("MATOSLA_LISTEN_HOST","*");
	ListenPort = cfg_getstr("MATOSLA_LISTEN_PORT","9423");
	BindHost = cfg_getstr("BIND_HOST","*");
	MaxReconnect = cfg_getuint32("MAX_RECONNECT",10);
	sla_worker_addr[0].host = cfg_getstr("SLA_SYNC_WORKER_HOST_1","*");
	sla_worker_addr[0].port = cfg_getstr("SLA_SYNC_WORKER_PORT_1","9422");
        sla_worker_addr[1].host = cfg_getstr("SLA_SYNC_WORKER_HOST_2","*");
        sla_worker_addr[1].port = cfg_getstr("SLA_SSYNC_WORKER_PORT_2","9422");
        sla_worker_addr[2].host = cfg_getstr("SLA_SSYNC_WORKER_HOST_3","*");
        sla_worker_addr[2].port = cfg_getstr("SLA_SSYNC_WORKER_PORT_3","9422");
        sla_worker_addr[3].host = cfg_getstr("SLA_SSYNC_WORKER_HOST_4","*");
        sla_worker_addr[3].port = cfg_getstr("SLA_SSYNC_WORKER_PORT_4","9422");

	first_add_listen_sock = 0;
	lsock = tcpsocket();
	if (lsock<0) {
		MFSLOG(LOG_ERR,"matosla: socket error: %m");
		fprintf(msgfd,"master <-> metaloggers module: can't create socket\n");
		return -1;
	}
	tcpnonblock(lsock);
	tcpnodelay(lsock);
	tcpreuseaddr(lsock);
	if (sla_worker_addr_resolve()<0) {
		MFSLOG(LOG_NOTICE,"sla_worker_addr_resolve failed");
	}
	if (tcpsetacceptfilter(lsock)<0) {
		MFSLOG(LOG_NOTICE,"matosla: can't set accept filter: %m");
	}
	if (tcpstrlisten(lsock,ListenHost,ListenPort,1024)<0) {
		MFSLOG(LOG_ERR,"matosla: listen error: %m");
		fprintf(msgfd,"master <-> metaloggers module: can't listen on socket\n");
		return -1;
	}
	MFSLOG(LOG_NOTICE,"matosla: listen on %s:%s",ListenHost,ListenPort);
	fprintf(msgfd,"master <-> metaloggers module: listen on %s:%s\n",ListenHost,ListenPort);

	matoslaservhead = NULL;
	main_destructregister(matoslaserv_term);
	main_epollregister(matoslaserv_desc,matoslaserv_serve);
	return 0;
}
Пример #6
0
int changelog_init() {
	BackLogsNumber = cfg_getuint32("BACK_LOGS",50);
	fd = NULL;
	//changelog_lock_init();
	return 0;
}
Пример #7
0
int masterconn_init() {
	uint32_t ReconnectionDelay;
	uint32_t MetaDLFreq;
	serventry *eptr;

	ReconnectionDelay = cfg_getuint32("MASTER_RECONNECTION_DELAY",5);
	MasterHost = cfg_getstr("MASTER_HOST","mfsmaster");
	MasterPort = cfg_getstr("MASTER_PORT","9423");
	BindHost = cfg_getstr("BIND_HOST","*");
	Timeout = cfg_getuint32("MASTER_TIMEOUT",60);
	BackLogsNumber = cfg_getuint32("BACK_LOGS",50);
	MetaDLFreq = cfg_getuint32("META_DOWNLOAD_FREQ",24);
	ListenHost = cfg_getstr("SYNC_THREAD_LISTEN_HOST","*");
	ListenPort = cfg_getstr("SYNC_THREAD_LISTEN_PORT","9422");

	first_add = 0;
	listen_add = 0;

	if (Timeout>65536) {
		Timeout=65535;
	}
	if (Timeout<=1) {
		Timeout=2;
	}
	if (BackLogsNumber<5) {
		BackLogsNumber=5;
	}
	if (BackLogsNumber>10000) {
		BackLogsNumber=10000;
	}
	if (MetaDLFreq>(BackLogsNumber/2)) {
		MetaDLFreq=BackLogsNumber/2;
	}
	

	masterconnsingleton = (serventry *)malloc(sizeof(serventry));
	eptr = masterconnsingleton;

	eptr->masteraddrvalid = 0;
	eptr->mode = FREE;
	eptr->logfd = NULL;
	eptr->metafd = -1;
	eptr->connection = 3;
	eptr->listen_sock = 0;

	if (masterconn_initlisten()<0) {
               	return -1;
        }

	if (masterconn_initconnect(eptr)<0) {
		return -1;
	}
	

	main_destructregister(masterconn_term);
	main_epollregister(masterconn_desc,masterconn_serve);
//	main_reloadregister(masterconn_reload);
//	main_timeregister(TIMEMODE_RUNONCE,MetaDLFreq*3600,630,masterconn_metadownloadinit);
//	main_timeregister(TIMEMODE_RUNONCE,60,0,masterconn_sessionsdownloadinit);
	(void)msgfd;
	return 0;
}
Пример #8
0
int main(int argc,char **argv) {
	char *logappname;
//	char *lockfname;
	char *wrkdir;
	char *cfgfile;
	char *appname;
	int ch;
	uint8_t runmode;
	int rundaemon,logundefined;
	int lockmemory;
	int32_t nicelevel;
	uint32_t locktimeout;
	int fd;
	uint8_t movewarning;
	struct rlimit rls;

	strerr_init();
	mycrc32_init();

	movewarning = 0;
	cfgfile=strdup(ETC_PATH "/mfs/" STR(APPNAME) ".cfg");
	passert(cfgfile);
	if ((fd = open(cfgfile,O_RDONLY))<0 && errno==ENOENT) {
		free(cfgfile);
		cfgfile=strdup(ETC_PATH "/" STR(APPNAME) ".cfg");
		passert(cfgfile);
		if ((fd = open(cfgfile,O_RDONLY))>=0) {
			movewarning = 1;
		}
	}
	if (fd>=0) {
		close(fd);
	}
	locktimeout = 1800;
	rundaemon = 1;
	runmode = RM_RESTART;
	logundefined = 0;
	lockmemory = 0;
	appname = argv[0];

	while ((ch = getopt(argc, argv, "uvdfsc:t:h?")) != -1) {
		switch(ch) {
			case 'v':
				printf("version: %u.%u.%u\n",VERSMAJ,VERSMID,VERSMIN);
				return 0;
			case 'd':
				rundaemon=0;
				break;
			case 'f':
				runmode=RM_START;
				break;
			case 's':
				runmode=RM_STOP;
				break;
			case 't':
				locktimeout=strtoul(optarg,NULL,10);
				break;
			case 'c':
				free(cfgfile);
				cfgfile = strdup(optarg);
				passert(cfgfile);
				movewarning = 0;
				break;
			case 'u':
				logundefined=1;
				break;
			default:
				usage(appname);
				return 1;
		}
	}
	argc -= optind;
	argv += optind;
	if (argc==1) {
		if (strcasecmp(argv[0],"start")==0) {
			runmode = RM_START;
		} else if (strcasecmp(argv[0],"stop")==0) {
			runmode = RM_STOP;
		} else if (strcasecmp(argv[0],"restart")==0) {
			runmode = RM_RESTART;
		} else if (strcasecmp(argv[0],"reload")==0) {
			runmode = RM_RELOAD;
		} else if (strcasecmp(argv[0],"test")==0) {
			runmode = RM_TEST;
		} else if (strcasecmp(argv[0],"kill")==0) {
			runmode = RM_KILL;
		} else {
			usage(appname);
			return 1;
		}
	} else if (argc!=0) {
		usage(appname);
		return 1;
	}

	if (movewarning) {
		mfs_syslog(LOG_WARNING,"default sysconf path has changed - please move " STR(APPNAME) ".cfg from "ETC_PATH"/ to "ETC_PATH"/mfs/");
	}

	if ((runmode==RM_START || runmode==RM_RESTART) && rundaemon) {
		makedaemon();
	} else {
		if (runmode==RM_START || runmode==RM_RESTART) {
			set_signal_handlers(0);
		}
	}

	if (cfg_load(cfgfile,logundefined)==0) {
		fprintf(stderr,"can't load config file: %s - using defaults\n",cfgfile);
	}
	free(cfgfile);

	logappname = cfg_getstr("SYSLOG_IDENT",STR(APPNAME));

	if (rundaemon) {
		if (logappname[0]) {
			openlog(logappname, LOG_PID | LOG_NDELAY , LOG_DAEMON);
		} else {
			openlog(STR(APPNAME), LOG_PID | LOG_NDELAY , LOG_DAEMON);
		}
	} else {
#if defined(LOG_PERROR)
		if (logappname[0]) {
			openlog(logappname, LOG_PID | LOG_NDELAY | LOG_PERROR, LOG_USER);
		} else {
			openlog(STR(APPNAME), LOG_PID | LOG_NDELAY | LOG_PERROR, LOG_USER);
		}
#else
		if (logappname[0]) {
			openlog(logappname, LOG_PID | LOG_NDELAY, LOG_USER);
		} else {
			openlog(STR(APPNAME), LOG_PID | LOG_NDELAY, LOG_USER);
		}
#endif
	}

	if (runmode==RM_START || runmode==RM_RESTART) {
		rls.rlim_cur = MFSMAXFILES;
		rls.rlim_max = MFSMAXFILES;
		if (setrlimit(RLIMIT_NOFILE,&rls)<0) {
			syslog(LOG_NOTICE,"can't change open files limit to %u",MFSMAXFILES);
		}

		lockmemory = cfg_getnum("LOCK_MEMORY",0);
#ifdef MFS_USE_MEMLOCK
		if (lockmemory) {
			rls.rlim_cur = RLIM_INFINITY;
			rls.rlim_max = RLIM_INFINITY;
			setrlimit(RLIMIT_MEMLOCK,&rls);
		}
#endif
		nicelevel = cfg_getint32("NICE_LEVEL",-19);
		setpriority(PRIO_PROCESS,getpid(),nicelevel);
	}

	changeugid();

	wrkdir = cfg_getstr("DATA_PATH",DATA_PATH);
	if (runmode==RM_START || runmode==RM_RESTART) {
		fprintf(stderr,"working directory: %s\n",wrkdir);
	}

	if (chdir(wrkdir)<0) {
		mfs_arg_syslog(LOG_ERR,"can't set working directory to %s",wrkdir);
		if (rundaemon) {
			fputc(0,stderr);
			close_msg_channel();
		}
		closelog();
		free(logappname);
		return 1;
	}
	free(wrkdir);

	umask(cfg_getuint32("FILE_UMASK",027)&077);

	/* for upgrading from previous versions of MFS */
	if (check_old_locks(runmode,locktimeout)<0) {
		if (rundaemon) {
			fputc(0,stderr);
			close_msg_channel();
		}
		closelog();
		free(logappname);
		wdunlock();
		return 1;
	}

	if (wdlock(runmode,locktimeout)<0) {
		if (rundaemon) {
			fputc(0,stderr);
			close_msg_channel();
		}
		closelog();
		free(logappname);
		wdunlock();
		return 1;
	}

	remove_old_wdlock();

	if (runmode==RM_STOP || runmode==RM_KILL || runmode==RM_RELOAD || runmode==RM_TEST) {
		if (rundaemon) {
			close_msg_channel();
		}
		closelog();
		free(logappname);
		wdunlock();
		return 0;
	}

#ifdef MFS_USE_MEMLOCK
	if (lockmemory) {
		if (getrlimit(RLIMIT_MEMLOCK,&rls)<0) {
			mfs_errlog(LOG_WARNING,"error getting memory lock limits");
		} else {
			if (rls.rlim_cur!=RLIM_INFINITY && rls.rlim_max==RLIM_INFINITY) {
				rls.rlim_cur = RLIM_INFINITY;
				rls.rlim_max = RLIM_INFINITY;
				if (setrlimit(RLIMIT_MEMLOCK,&rls)<0) {
					mfs_errlog(LOG_WARNING,"error setting memory lock limit to unlimited");
				}
			}
			if (getrlimit(RLIMIT_MEMLOCK,&rls)<0) {
				mfs_errlog(LOG_WARNING,"error getting memory lock limits");
			} else {
				if (rls.rlim_cur!=RLIM_INFINITY) {
					mfs_errlog(LOG_WARNING,"can't set memory lock limit to unlimited");
				} else {
					if (mlockall(MCL_CURRENT|MCL_FUTURE)<0) {
						mfs_errlog(LOG_WARNING,"memory lock error");
					} else {
						mfs_syslog(LOG_NOTICE,"process memory was successfully locked in RAM");
					}
			}	}
		}
	}
#else
	if (lockmemory) {
		mfs_syslog(LOG_WARNING,"memory lock not supported !!!");
	}
#endif
	fprintf(stderr,"initializing %s modules ...\n",logappname);

	if (initialize()) {
		if (getrlimit(RLIMIT_NOFILE,&rls)==0) {
			syslog(LOG_NOTICE,"open files limit: %lu",(unsigned long)(rls.rlim_cur));
		}
		fprintf(stderr,"%s daemon initialized properly\n",logappname);
		if (rundaemon) {
			close_msg_channel();
		}
		if (initialize_late()) {
			mainloop();
			ch=0;
		} else {
			ch=1;
		}
	} else {
		fprintf(stderr,"error occured during initialization - exiting\n");
		if (rundaemon) {
			fputc(0,stderr);
			close_msg_channel();
		}
		ch=1;
	}
	destruct();
	free_all_registered_entries();
	signal_cleanup();
	cfg_term();
	strerr_term();
	closelog();
	free(logappname);
	wdunlock();
	return ch;
}