Beispiel #1
0
################################# START OF PROGRAM ##########################################
#############################################################################################
#############################################################################################
daemonize()

import config
import unixIPC
import exec_cmd_pb2
import exec_resp_pb2
import google.protobuf


config.force_load()
# start IPC server
unixIPC = unixIPC.UnixIPC()
unixIPC.run_server("mod_exec", int(config.map["mod_exec"]["port"]))

modules = []
for mod in config.map["mod_exec"]["modules"]:
    try:
        (startup_state, delay, name, cmd) = mod.split(",")
    except ValueError, e:
        print 'ERROR: Invalid mod_exec line: "' + mod + '"'
        continue

    proc = ExecProcess()
    proc.cmd = cmd
    proc.delay_start = int(delay)
    proc.countdown = 0
    proc.name = name
        
    os.kill(child.process.pid, signal.SIGCONT)
    child.status = scheduledb.RUNNING
    scheduledb.update_task(child.task,'status',child.status)
    
# connect to postgres
scheduledb.connect()
if scheduledb.connected():
    scheduledb.initdb()
else:
    print "ERROR: Cannot connect to postgre database"
    sys.exit(1)

# host unix socket
unixIPC = unixIPC.UnixIPC();
unixIPC.run_server("mod_scheduler", int(config.map['mod_scheduler']['port']));

# the subprocesses
children = []

#timeouts
last_db_check = time.time()

while True:
    if ( not scheduledb.connected() ):
        scheduledb.connect()
    else:
        if ( time.time() - last_db_check > DB_CHECK_INTERVAL ):
            check_db()
            last_db_check = time.time()
        
import config_cmd_pb2;
import config_resp_pb2;
import google.protobuf


    
config.force_load();

cmap = config.map;
   
    
############# START THE SERVER ############################

unixIPC = unixIPC.UnixIPC();
unixIPC.run_server("mod_config", mod_config_IF.CONFIG_PORT);

while(1):
    if not unixIPC.connected:
        unixIPC.reconnect();
    else:
        msgs = unixIPC.tick();
        for (mtype, msg, client) in msgs:
            #print "Got message of type ",type," : ",msg
            if mtype == 'config_cmd_pb2':
                config_cmd_msg = config_cmd_pb2.Config_Cmd()
                try:
                    config_cmd_msg.ParseFromString(msg)
                    if config_cmd_msg.cmd == config_cmd_pb2.Config_Cmd.SET:
                        mod_name = config_cmd_msg.mod_name;
                        key = config_cmd_msg.key;