armchair dot tech
Gate One supervisor script | ABOUT | TAGS

August 2, 2012 | TAGS:

Yesterday, I setup gateone to run as a non-root user. I also spent some time looking at potential init scripts for starting and stopping this. The gateone project does not currently provide any init scripts, but this is planned for the future ([Issue #47]). I tried to use one of the scripts in that thread, but I wasn’t really pleased with them. The big issue is that doesn’t fork. However, I believe there is a better solution.

supervisord is a python script designed to control and monitor non-daemonizing python scripts. As Gate One is a foreground only process, it seems particularly suited to this task - more so than writing my own script in python or daemontools.

Installation can be done with python-pip or easy_install. On newer systems, pip is recommended.

On Ubuntu, pip installs supervisord to /usr/local/bin. By default, /usr/local/bin is not in root’s path, so it makes sense (to me at least) to create symlinks to /usr/sbin.

Now, we need to create a configuration file. Supervisord has a utility to generate a sample one.

To get started, we can use the sample configuration and just add a couple lines to the bottom for gateone.

Now, copy supervisord.conf to /etc/supervisord.conf and start supervisord. Make sure is not currently running. Then we’ll run supervisorctl to test things out.

In this example, we see that is started and stopped by supervisorctl, but because we have dtach enabled, our sessions are still in place. If we restart, we can connect to it again and have our sessions resumed. While we could probably configure supervisord to kill these terminals, I believe we’d normally want to keep them running. The few times I would want to stop those terminals would be a) manually reconfiguring/troubleshooting opengate, b) updating software, or c) rebooting the server. For a&b, running the command “ -kill” will kill those terminals. For a server shutdown or reboot, the act of shutting down the OS will kill these terminals.

Finally, we need a way to start and stop supervisord itself. Fortunately, the supervisord project has provided a number of init scripts. I was able to use the Debian script in Ubuntu with only a few minor changes.

Here is my complete init script for Ubuntu:

And here is a complete copy of my supervisord.conf file: