@@ -0,0 +1,2720 @@
+'''%0AThe default service module, if not otherwise specified salt will fall back%0Ato this basic module%0A'''%0A%0Aimport os%0A%0A%0Adef __virtual__():%0A    '''%0A    Only work on systems which default to systemd%0A    '''%0A    # Disable on these platforms, specific service modules exist:%0A    if __grains__%5B'os'%5D == 'FreeBSD':%0A        return 'service'%0A    return False%0A%0Adef get_enabled():%0A    '''%0A    Return what services are set to run on boot%0A    '''%0A    ret = %5B%5D%0A    for rcfn in ('/etc/rc.conf', '/etc/rc.conf.local'):%0A        if os.path.isfile(rcfn):%0A            for line in open(rcfn, 'r').readlines():%0A                if not line.strip():%0A                    continue%0A                if line.startswith('#'):%0A                    continue%0A                if not '_enable' in line:%0A                    continue%0A                if not '=' in line:%0A                    continue%0A                comps = line.split('=')%0A                if 'YES' in comps%5B1%5D:%0A                    # Is enabled!%0A                    ret.append(comps%5B0%5D.split('_')%5B0%5D)%0A    return ret%0A%0A%0Adef get_disabled():%0A    '''%0A    Return what services are available but not enabled to start at boot%0A    '''%0A    en_ = get_enabled()%0A    all_ = get_all()%0A    return sorted(set(all_).difference(set(en_)))%0A%0A%0Adef get_all():%0A    '''%0A    Return a list of all available services%0A    '''%0A    ret = set()%0A    for rcdir in ('/etc/rc.d/', '/usr/local/etc/rc.d/'):%0A        ret.update(os.listdir(rcdir))%0A    rm_ = set()%0A    for srv in ret:%0A        if srv.isupper():%0A            rm_.add(srv)%0A    ret.difference(rm_)%0A    return sorted(ret)%0A%0A%0Adef start(name):%0A    '''%0A    Start the specified service%0A%0A    CLI Example::%0A%0A        salt '*' service.start %3Cservice name%3E%0A    '''%0A    cmd = 'service %7B0%7D onestart'.format(name)%0A    return not __salt__%5B'cmd.retcode'%5D(cmd)%0A%0A%0Adef stop(name):%0A    '''%0A    Stop the specified service%0A%0A    CLI Example::%0A%0A        salt '*' service.stop %3Cservice name%3E%0A    '''%0A    cmd = 'service %7B0%7D onestop'.format(name)%0A    return not __salt__%5B'cmd.retcode'%5D(cmd)%0A%0A%0Adef restart(name):%0A    '''%0A    Restart the named service%0A%0A    CLI Example::%0A%0A        salt '*' service.restart %3Cservice name%3E%0A    '''%0A    cmd = 'service %7B0%7D onerestart'.format(name)%0A    return not __salt__%5B'cmd.retcode'%5D(cmd)%0A%0A%0Adef status(name, sig=None):%0A    '''%0A    Return the status for a service, returns the PID or an empty string if the%0A    service is running or not, pass a signature to use to find the service via%0A    ps%0A%0A    CLI Example::%0A%0A        salt '*' service.status %3Cservice name%3E %5Bservice signature%5D%0A    '''%0A    sig = name if not sig else sig%0A    cmd = %22%7B0%5Bps%5D%7D %7C grep %7B1%7D %7C grep -v grep %7C awk '%7B%7Bprint $2%7D%7D'%22.format(%0A            __grains__, sig)%0A    return __salt__%5B'cmd.run'%5D(cmd).strip()%0A%0A%0A

add initial freebsdservice module