Spring boot application is built into a jar which contains its own tomcat. So instead of running it in a traditional way of having a tomcat instance that serving one or multiple wars, we will run the jar with java -jar. The problem here is if we run it directly, when our session quits/expires, the process will end. So we can either run it as a service(init.d), or using some 3rd party tool to manage it. In NodeJs world, we have the super powerful pm2. in the native world, ‘supervisor‘ seems to be the most recommended tool. Here we are going to introduce how to manage our spring boot jar with supervisor.
Some EC2 AMI comes with ‘easy_install’, which is a feature of setuptools. This is the preferred method of installation.
Depending on the permissions of your system’s Python, you might need to be the root user to install Supervisor successfully using easy_install.
Or we can use pip to install it thru:
pip install supervisor
More reference in their official doc.
The Supervisor configuration file is conventionally named supervisord.conf. It is used by both supervisord and supervisorctl. If either application is started without the -coption (the option which is used to tell the application the configuration filename explicitly), the application will look for a file named supervisord.conf within the following locations, in the specified order. It will use the first file it finds.
- /etc/supervisor/supervisord.conf (since Supervisor 3.3.0)
- ../etc/supervisord.conf (Relative to the executable)
- ../supervisord.conf (Relative to the executable)
Below is the supervisord.conf i use for ADDS jar which i placed under /etc
in the ‘include’ section above, we want the supervisor to get all the conf files under conf.d. So now we can create a adds.conf there:
Run supervisord and its control
Now we can run ‘supervisord’ or sudo supervisord to start the daemon.
To fine control the processes, we can use the `supervisorctl` tool.Enter supervisorctl alone will take us the to interactive shell. and there are many actions we can take. use `help` to get the list.
So here we can do start/stop/restart/status…etc, a lot of stuff.
Or we can run it directly using something like: `supervisorctl restart adds`.
Web control console
We could access the supervisor control via http://IP:9001 and manage process there directly.