Skip to content

Instantly share code, notes, and snippets.

@pSub
Created May 2, 2012 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pSub/2577133 to your computer and use it in GitHub Desktop.
Save pSub/2577133 to your computer and use it in GitHub Desktop.
Use daemons uniformly
# 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