Skip to content

Instantly share code, notes, and snippets.

@ches
Created April 14, 2011 07:43
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save ches/919084 to your computer and use it in GitHub Desktop.
Save ches/919084 to your computer and use it in GitHub Desktop.
A quick script to switch between running Pow and Apache on OS X
#!/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
@javve
Copy link

javve commented Jun 26, 2011

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

@ches
Copy link
Author

ches commented Jun 26, 2011

@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.

@ches
Copy link
Author

ches commented Aug 27, 2011

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment