def read_require_fields_from_target_file(fil): config, prog, is_service = create_config(fil) if config == 1: wyslog("Error initialising target file: " + fil) return [1, 1] options = ["After", "Requires"] requires = set() for option in options: if config.has_option("Unit", option): after_services_str = config.get("Unit", option)[0] for unit in after_services_str.split(" "): if ( unit != "rescue.target" and unit != "rescue.service" and unit != "emergency.target" and unit != "emergency.service" ): requires.add(unit) # required_str += unit + " " # print prog + ": " return requires, is_service
def read_wants_from_target_file(fil): config, prog, is_service = create_config(fil) if config == 1: wyslog('Error initialising target file: ' + fil) return 1 wants_path = '/etc/systemd/system/' + prog + '.target.wants/' options = ['Wants'] wants = set() for option in options: if config.has_option("Unit", option): after_services_str = config.get("Unit", option)[0] for unit in after_services_str.split(" "): # ignore any references to rescue or emergency if unit != "rescue.target" and unit != "rescue.service" and unit != "emergency.target" and unit != "emergency.service": wants.add(unit) else: break if not is_service and os.path.isdir(wants_path): wantsfiles = [ f for f in os.listdir(wants_path) if os.path.isfile(os.path.join(wants_path, f)) ] # add list to set wants |= set(wantsfiles) # special case for "default.target" if not is_service and prog == "default": # get the real name of the target, i.e. graphical real_target = os.path.basename( os.readlink('/etc/systemd/system/default.target')).replace( ".target", "") # create the wants path for the real target, create the list of files and append them to the wants set real_wants_path = '/etc/systemd/system/' + real_target + '.target.wants/' if os.path.isdir(real_wants_path): real_wantsfiles = [ f for f in os.listdir(real_wants_path) if os.path.isfile(os.path.join(real_wants_path, f)) ] wants |= set(real_wantsfiles) return wants
def read_wants_from_target_file(fil): config, prog, is_service = create_config(fil) if config == 1: wyslog("Error initialising target file: " + fil) return 1 wants_path = "/etc/systemd/system/" + prog + ".target.wants/" options = ["Wants"] wants = set() for option in options: if config.has_option("Unit", option): after_services_str = config.get("Unit", option)[0] for unit in after_services_str.split(" "): # ignore any references to rescue or emergency if ( unit != "rescue.target" and unit != "rescue.service" and unit != "emergency.target" and unit != "emergency.service" ): wants.add(unit) else: break if not is_service and os.path.isdir(wants_path): wantsfiles = [f for f in os.listdir(wants_path) if os.path.isfile(os.path.join(wants_path, f))] # add list to set wants |= set(wantsfiles) # special case for "default.target" if not is_service and prog == "default": # get the real name of the target, i.e. graphical real_target = os.path.basename(os.readlink("/etc/systemd/system/default.target")).replace(".target", "") # create the wants path for the real target, create the list of files and append them to the wants set real_wants_path = "/etc/systemd/system/" + real_target + ".target.wants/" if os.path.isdir(real_wants_path): real_wantsfiles = [ f for f in os.listdir(real_wants_path) if os.path.isfile(os.path.join(real_wants_path, f)) ] wants |= set(real_wantsfiles) return wants
def read_require_fields_from_target_file(fil): config, prog, is_service = create_config(fil) if config == 1: wyslog('Error initialising target file: ' + fil) return [1, 1] options = ['After', 'Requires'] requires = set() for option in options: if config.has_option("Unit", option): after_services_str = config.get("Unit", option)[0] for unit in after_services_str.split(" "): if unit != "rescue.target" and unit != "rescue.service" and unit != "emergency.target" and unit != "emergency.service": requires.add(unit) # required_str += unit + " " # print prog + ": " return requires, is_service
def start_service(fil): config, prog, is_service = create_config(fil) unitname = os.path.splitext(os.path.basename(fil))[0] if config == 1: wyslog('Error initialising target file: ' + fil) return [1, 1] print bcolors.HEADER + "[WARLOCK]" + bcolors.BOLD + " Starting " + unitname + "..." + bcolors.ENDC actions = ['ExecStartPre', 'ExecStart', 'ExecStartPost'] for action in actions: if config.has_option("Service", action): print "starting action " + action if _start(action, config, fil): print action + " completed successfully for " + unitname else: print action + " failed for " + unitname print bcolors.HEADER + "[WARLOCK]" + bcolors.BOLD + " Started: " + unitname + bcolors.ENDC wyslog("Started: " + unitname) return
def start_service(fil): config, prog, is_service = create_config(fil) unitname = os.path.splitext(os.path.basename(fil))[0] if config == 1: wyslog("Error initialising target file: " + fil) return [1, 1] print bcolors.HEADER + "[WARLOCK]" + bcolors.BOLD + " Starting " + unitname + "..." + bcolors.ENDC actions = ["ExecStartPre", "ExecStart", "ExecStartPost"] for action in actions: if config.has_option("Service", action): print "starting action " + action if _start(action, config, fil): print action + " completed successfully for " + unitname else: print action + " failed for " + unitname print bcolors.HEADER + "[WARLOCK]" + bcolors.BOLD + " Started: " + unitname + bcolors.ENDC wyslog("Started: " + unitname) return