Created
November 24, 2011 17:42
-
-
Save fipar/1391884 to your computer and use it in GitHub Desktop.
As I miss service from RH when using ports.
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
#!/bin/bash | |
#rh-like service primitive wrapper for launchctl | |
usage() | |
{ | |
echo "usage: service <name> <start|stop>">&2 | |
} | |
[ $# -ne 2 ] && { | |
usage | |
exit 1 | |
} | |
service_name=$1 | |
action=$2 | |
[ -z "$action" ] && { | |
usage | |
exit 1 | |
} | |
target=$(find /Library/LaunchDaemons -name "*$service_name*" 2>/dev/null) | |
cnt=$(echo $target|tr ' ' '\n'|wc -l) | |
[ -z "$target" ] && { | |
echo "Nothing found for $service_name under /Library/LaunchDaemons">&2 | |
exit 1 | |
} | |
[ $cnt -gt 1 ] && { | |
echo "Too many matches. Be more specific. Matches: " | |
echo $target|tr ' ' '\n' | |
exit 1 | |
} | |
case $action in | |
"start") sudo launchctl load -w $target;; | |
"stop") sudo launchctl unload -w $target;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment