Skip to content

Instantly share code, notes, and snippets.

@r10r
Last active December 27, 2015 09:29
Show Gist options
  • Save r10r/7304561 to your computer and use it in GitHub Desktop.
Save r10r/7304561 to your computer and use it in GitHub Desktop.
Relaunch daemons controlled by launchd easily.
dnsmasq=homebrew.mxcl.dnsmasq
postgres=homebrew.mxcl.postgresql
#!/bin/sh
# About: Relaunch daemons controlled by launchd easily.
# Usage: $0 $command $label
# Example: relaunch homebrew.mxcl.dnsmasq
# Label mappings can be defined in $mapping
# label mappings
mapping=$HOME/.launchd_aliases
label=$2
command=$1
label_alias=`[ -f $mapping ] && grep $label $mapping | cut -d'=' -f2`
label=${label_alias:-$label}
echo "lctl: $command $label"
case $command in
start|stop)
exec launchctl $command $label
;;
load|unload)
exec launchctl $command /Library/LaunchDaemons/${label}.plist
;;
restart)
exec sh <<-END
launchctl stop $label
launchctl start $label
END
;;
reload)
exec sh <<-END
launchctl unload /Library/LaunchDaemons/${label}.plist
launchctl load /Library/LaunchDaemons/${label}.plist
END
;;
*)
echo "No such command: $command"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment