How to reload macports without unload, load
March 8th, 2013
I've been using macports ever since I switched to the macbook pro a couple of years ago. It's a very fine ports collection that uses very straightforward commands to do whatever is it you want to do.
But when you install ports that need to be running to use them (like a webserver or a database server or even php-fpm) there's often a need to stop/start those services. And here's where macports falls short... Macports uses the OSX launchctl command, and only adds individual commands to stop, and then start a service.
This can become tedious:
sudo port unload nginx && sudo port load nginx
Googling this issue I came across this feature request, which illustrates the "problem". Obviously, there's more than one way to skin a cat (and absolutely no reason why you would want to?!)
So here's a simple bash script to join the two commands together.
#!/usr/bin/env bash SUDO="/usr/bin/sudo" PORT="/opt/local/bin/port" if [ $# -lt 1 ]; then echo "Usage: portreload portname [portname] ..."; exit; fi for p in $@ do $SUDO $PORT unload $p \ && $SUDO $PORT load $p \ && echo "Port $p reloaded"; done
To use it, save the contents to a file called "portreload" (or something else of your choice), save it in your path and make in executable. Then you can do:
portreload nginx mysql5 php54-fpm
And it will output the result:
Port nginx reloaded Port mysql5 reloaded Port php54-fpm reloaded
Pointy haired boss
Want to learn more? Join us at Future500
We are always looking for new colleagues that want to learn with us.
Check out our vacancies or write us at firstname.lastname@example.org