Last active
December 27, 2015 09:29
-
-
Save r10r/7304561 to your computer and use it in GitHub Desktop.
Relaunch daemons controlled by launchd easily.
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
dnsmasq=homebrew.mxcl.dnsmasq | |
postgres=homebrew.mxcl.postgresql |
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/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