svc.sh: support systemd

This commit is contained in:
mollusk 2021-10-23 20:26:23 -07:00
parent d1e9c221a3
commit 84a19253c0

70
svc.sh
View File

@ -31,6 +31,17 @@ LPURPLE="\033[1;35m"
BWHITE="\e[1m" BWHITE="\e[1m"
NC='\033[0m' # No Color 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(){ help(){
printf """ printf """
svc - Service Commander - frontend for the sv command svc - Service Commander - frontend for the sv command
@ -53,6 +64,7 @@ up Show status of running services
""" """
} }
runit(){
case $1 in case $1 in
enable | --enable-service ) enable | --enable-service )
@ -99,3 +111,61 @@ case $1 in
help help
;; ;;
esac 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