Whether in daily work or usually play code, I always inseparable from Supervisor, in fact, a long time ago I wrote an article: Supervisord deployment Flask, in which I carefully explained how to install and configure the Supervisord in the Linux environment, And how to deploy the application, you should know a little bit of Linux students can follow the guidance of their own environment to configure a copy out. However, I am more in the case of daily work under the Mac, although the Mac already has a lot of powerful tools to keep my work efficient, but there are some things that the software on the MAC is not available to me, so I still rely on supervisor, so this article will explain how the Mac Environment to configure a good process management environment.
Configuring Supervisor Self-booting
For simple installation configuration supervisor not much to say, or simple to use PIP can be installed, supervisor's own configuration can also refer to my previous article Supervisord deployment flask. However, this is not enough because my computer is going to be restarted (yes, the MAC will be restarted, I'll reboot in about half a month or one months). By default, after the restart Supervisor is not up, so I have to manually let it up, and then to drive my other software up, this is not very comfortable, so I would like to be able to adjust the configuration, let Supervisor self-booting.
After a search, it was found that there is an systemd-like application in the Mac named: Launchd,launchd is an important process that OSX uses to initialize the system, which is the first process that starts in the OS environment after the kernel has been loaded successfully (as if it were a bad one). Also, it is interesting to note that registering an application in Launchd is simple and requires only one plist file, usually the plist file is placed under the directory ~/library/launchagents
. So I wrote a leaf out. config:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict> <key>KeepAlive</key> <dict> <key>SuccessfulExit</key> <false/> </dict> <key>Label</key> <string>io.liqiang.supervisord</string> <key>ProgramArguments</key> <array> <string>/usr/local/bin/supervisord</string> <string>-n</string> <string>-c</string> <string>/usr/local/share/supervisor/supervisord.conf</string> </array> <key>RunAtLoad</key> <true/></dict></plist>
Test process
The truth is that this is the end of the story. However, in order for everyone to have a better verification experience, so I added a MongoDB configuration, if you are interested, the default configuration should be placed in: /usr/local/share/supervisor/conf.d/mongod.conf
This location, the configuration content is:
[program:mongod]command=/usr/local/mongodb/bin/mongod -f /data/conf/mongodb.yamlautostart=falseautorestart=falsestartretries=3redirect_stderr=truestdout_logfile = /var/log/supervisord_mongodb.logloglevel=infoexitcodes=1,2
After this configuration is done, it still looks the same:
$ supervisorctl reread$ supervisorctl update$ supervisorctl start mongod
Here should MongoDB is up, now connect up and try.
Reference
- Setting up Supervisord in Mac OS X
MAC Supervisor Management Process