Last active
December 27, 2017 22:08
-
-
Save notbrain/b7c3d2eb83250419e5b63f619a0d4b78 to your computer and use it in GitHub Desktop.
control script for stopping and restarting macOS launchctl agents
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 -e | |
# Why is there no launchtl restart or reload? Tsk. | |
# | |
cmd=$1 | |
plistfile="$HOME/Library/LaunchAgents/homebrew.mxcl.mariadb.plist"; | |
ps_grep_string="mysql"; | |
function ps_grep() { | |
ps aux | grep -e $ps_grep_string | grep -v 'grep'; | |
} | |
case "$cmd" in | |
'start') | |
echo "Loading $plistfile"; | |
launchctl load -F $plistfile; | |
sleep 5; | |
ps_grep; | |
;; | |
'stop') | |
echo "Unloading $plistfile"; | |
launchctl unload -F $plistfile; | |
sleep 3; | |
ps_grep; | |
;; | |
'restart') | |
echo "Unloading and loading $plistfile"; | |
launchctl unload -F $plistfile \ | |
&& sleep 3 \ | |
&& launchctl load -F $plistfile; | |
sleep 5; | |
ps_grep; | |
;; | |
'check') | |
ps_grep; | |
;; | |
*) | |
# usage | |
basename=`basename "$0"` | |
echo "Usage: $basename {check|start|stop|restart}" | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment