A quick one that hopefully my geeky friends, followers and random Google searchers will appreciate – a way to restart all services being managed by the popular Daemontool’s supervise package on Linux.
We use supervise extensively for running our various custom daemons that power AffinityLive, and because we’re doing very rapid development releases we’ve recently been seeing some problems with module code at the heart of our app being updated, yet our various daemons not being kicked, and thus using out of date code. There’s the great svc command that you can use to kill a particular process, but doing them all as bulk doesn’t work (unless you’re in as the fully fledged root user, but that isn’t a smart thing to do on live production systems).
To solve this, I wrote a one-line bash script. While not tricky or complicated, the tight permission controls over the supervise directories made it a little more fun than the hello world examples out there.
So, if you want to restart every single process being supervised on a particular server, here’s how:
for i in `sudo ls /var/lib/service/`; do sudo svc -k “/var/lib/service/$i”; done
Of course, if you don’t want to be so brutal as to kill your supervised process, and instead want to send it a HUP or an ALARM, or, if you want to stop all supervised processes for some reason, you can sub out the -k for the other arguments detailed on the svc man page.
Hope that is useful to someone else out there sometime!