public
ches / pow
Last active

A quick script to switch between running Pow and Apache on OS X

  • Download Gist
pow
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#!/bin/sh -e
#/ Usage: pow [on|off]
#/ Toggle between running Pow (http://pow.cx) and Apache on Mac OS X.
 
# Show Usage
function usage {
grep '^#/' "$0" | cut -c4-
exit 2
}
[ -z "$1" -o "$1" = "--help" ] && usage
 
# Fail fast if we're on OS X
if [ "$(uname -s)" != "Darwin" ]; then
echo "You're not on OS X, so methinks you're not running Pow." 1>&2
exit 1
fi
 
POWD_LAUNCHAGENT="$HOME/Library/LaunchAgents/cx.pow.powd.plist"
POW_FIREWALL_LAUNCHDAEMON="/Library/LaunchDaemons/cx.pow.firewall.plist"
APACHE_LAUNCHDAEMON="/System/Library/LaunchDaemons/org.apache.httpd.plist"
 
# Quick and dirty. Feel free to contribute nicer error handling, etc.
toggle="$1"
case "$toggle" in
'on')
sudo launchctl unload $APACHE_LAUNCHDAEMON
sudo launchctl load $POW_FIREWALL_LAUNCHDAEMON
launchctl load $POWD_LAUNCHAGENT && launchctl list | grep pow
;;
'off')
launchctl unload $POWD_LAUNCHAGENT
sudo launchctl unload $POW_FIREWALL_LAUNCHDAEMON
sudo ipfw show | grep ",20559 .* dst-port 80 in" | cut -d' ' -f1 | xargs sudo ipfw delete
sudo launchctl load $APACHE_LAUNCHDAEMON &&
sudo launchctl list | grep apache
;;
*)
usage
;;
esac

I get error
launchctl: Error unloading: cx.pow.powd
when writing
pow off

@Javve, that would happen if pow wasn't already running -- are you sure it was? Try pow on, see if pow is working as expected, then pow off. If you have any trouble, run the commands in the script one-by-one, and/or check Console.app for any issues launchd may be complaining about.

I should note that this is quick and dirty -- folks can feel free to add some ps-grep-checking or other error handling to avoid hitting insignificant errors like @javve saw. I'd also be remiss not to point out powify or powder if you want a more full-featured solution -- they're great, they're just overkill for me in this simplest of use cases.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.