Created
May 2, 2012 14:50
-
-
Save pSub/2577133 to your computer and use it in GitHub Desktop.
Use daemons uniformly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Handle the start/stop/restart and reload of daemons uniformly. | |
# It's able to handle multiple daemons. | |
start restart stop reload(){ | |
local daemonPath distro cmd | |
if [[ $# -le 0 ]]; then | |
echo "Usage: start [restart, stop, reload] DAEMON [DAEMON ...]" | |
return 1 | |
fi | |
distro=$(cat /etc/issue) | |
case $distro in | |
*"Arch Linux"*) | |
daemonPath="/etc/rc.d/" ;; | |
*"Debian GNU/Linux"*) | |
daemonPath="/etc/init.d/" ;; | |
*) | |
echo "Distro not supported" | |
exit 1 | |
esac | |
if [[ $UID = 0 ]]; then | |
foreach daemon ($*); do | |
$daemonPath$daemon $0 | |
done | |
else | |
foreach daemon ($*); do | |
cmd="$cmd $daemonPath$daemon $0;" | |
done | |
su --command="$cmd" | |
fi | |
unset daemonPath distro | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment