scripts/runctl/runctl.sh

49 lines
1.1 KiB
Bash
Raw Normal View History

2024-04-15 04:05:24 +00:00
#!/bin/bash
# This Snippet can be used as a script, placed in ~/.local/bin, or as a snippet in your ~/.bashrc
# Snippet Runit
runctl() {
if [ ! -d /etc/runit/sv/$2 ]
then
echo "Service $2 doesn't exist."
else
case $1 in
start)
echo Starting $2 ...
sudo sv start $2;;
stop)
echo Stopping $2 ...
sudo sv stop $2 ...;;
status)
if [ ! -d /run/runit/service/$2 ]
then echo "Service $2 is not enabled."
else sudo sv status $2
fi;;
enable)
echo Enabling $2 ...
if [ -d /run/runit/service/$2 ]
then echo "Service $2 is already enabled."
else sudo ln -s /etc/runit/sv/$2 /run/runit/service/
fi;;
disable)
echo Disabling $2 ...
sudo rm -rf /run/runit/service/$2;;
*)
echo "runctl is a bash snippet to easily manipulate runit services."
echo ""
echo "Usage :"
echo " runctl <option> <service>"
echo ""
echo "Options :"
echo " start / stop / status / enable / disable"
echo ""
echo "Exemples :"
echo " runctl enable syncthing"
echo " runctl status mpd"
echo " runctl start sshd"
echo ""
esac
fi
}