diff --git a/svc.sh b/svc.sh index c7122c9..244843d 100755 --- a/svc.sh +++ b/svc.sh @@ -31,6 +31,17 @@ LPURPLE="\033[1;35m" BWHITE="\e[1m" NC='\033[0m' # No Color +osType=$(lsb-release -a | grep Distributor | cut -d ':' -f 2,2) + +if [[ -f "/usr/bin/sv " ]];then + serviceManager="runit" +elif [[ -f "/usr/bin/systemctl" ]];then + serviceManager="systemd" +fi + + + + help(){ printf """ svc - Service Commander - frontend for the sv command @@ -53,49 +64,108 @@ up Show status of running services """ } -case $1 in +runit(){ + case $1 in - enable | --enable-service ) - ln -v -s /etc/sv/"${2}" /var/service/ - ;; + enable | --enable-service ) + ln -v -s /etc/sv/"${2}" /var/service/ + ;; - disable | --remove-service ) - rm -v /var/service/"${2}" - ;; + disable | --remove-service ) + rm -v /var/service/"${2}" + ;; - enabled | --enabled-services ) - cd /etc/sv && find -xtype l -exec ls -l {} \; - ;; + enabled | --enabled-services ) + cd /etc/sv && find -xtype l -exec ls -l {} \; + ;; - list | ls | --list ) + list | ls | --list ) - echo - echo -e "${LGREEN}Available Services (/etc/sv/):${NC}\n" - ls /etc/sv - echo - echo -e "${LCYAN}Enabled Services (/var/service):${NC}\n" - echo - ls /var/service - echo - ;; + echo + echo -e "${LGREEN}Available Services (/etc/sv/):${NC}\n" + ls /etc/sv + echo + echo -e "${LCYAN}Enabled Services (/var/service):${NC}\n" + echo + ls /var/service + echo + ;; - up ) - sv s /var/service/* - ;; + up ) + sv s /var/service/* + ;; - start ) - sv start "${2}" - ;; + start ) + sv start "${2}" + ;; - restart ) - sv restart "${2}" - ;; + restart ) + sv restart "${2}" + ;; - stop ) - sv stop "${2}" - ;; + stop ) + sv stop "${2}" + ;; - --help | -h | help ) - help - ;; -esac + --help | -h | help ) + help + ;; + esac +} + + +systemd(){ + + case "${1}" in + enable | --enable-service) + systemctl enable "${2}" + ;; + + disable | --disable-service) + systemctl disable "${2}" + ;; + + enabled | --enabled-services) + systemctl list-unit-files --state=enabled + ;; + + list | ls | --list) + echo + echo -e "${LGREEN}Available Services (/etc/systemd/system):${NC}\n" + ls /etc/systemd/system/ + echo + echo -e "${LCYAN}Enabled Services:${NC}\n" + systemctl list-unit-files --state=enabled + echo + ;; + up) + systemctl --type=service --state=running + ;; + + start) + systemctl start "${2}" + ;; + + restart) + systemctl restart "${2}" + ;; + + stop) + systemctl stop "${2}" + ;; + + --help | -help | help) + help + ;; + + + + + esac +} + +if [[ "${serviceManager}" = "runit" ]];then + runit "${1}" "${2}" +elif [[ "${serviceManager}" ]];then + systemd "${1}" "${2}" +fi \ No newline at end of file