Skip to content

Instantly share code, notes, and snippets.

@fipar
Created November 24, 2011 17:42
Show Gist options
  • Save fipar/1391884 to your computer and use it in GitHub Desktop.
Save fipar/1391884 to your computer and use it in GitHub Desktop.
As I miss service from RH when using ports.
#!/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