svc.sh: support systemd
This commit is contained in:
parent
d1e9c221a3
commit
84a19253c0
74
svc.sh
74
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,7 +64,8 @@ up Show status of running services
|
||||
"""
|
||||
}
|
||||
|
||||
case $1 in
|
||||
runit(){
|
||||
case $1 in
|
||||
|
||||
enable | --enable-service )
|
||||
ln -v -s /etc/sv/"${2}" /var/service/
|
||||
@ -98,4 +110,62 @@ case $1 in
|
||||
--help | -h | 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
|
Loading…
x
Reference in New Issue
Block a user