I’m sure you all have experience in managing Linux host processes and have used a variety of tools, but you are certainly no stranger to the Python version of Supervisor, which is a very useful tool. It can monitor different process states and can restart automatically. This article introduces the open source package “Supervisord” written in Go language, the author mentions why this tool is developed in Go language, the reason is simple. The reason is very simple, is that through the cross-platform advantage of Go language, write a set of programs, can directly run in any platform, the administrator no longer need to bother about the Python environment.
Usage Scenario
It’s 2021 and many tools and services are now managed through Docker. The tool that is needed is no longer the Supervisor, but there is a reason why the Supervisor is necessary. There are several situations in our team that require this tool.
- managing multiple processes in a Container
- no Docker environment
The first point is that if you manage Processes in a Container, you want to see the Python environment installed first, and the whole container will become very fat, which is the situation we need to consider. The second situation, like our team has an environment with no network at all, is also prohibited to use Docker, because Docker will make it very difficult for IT to manage the use of other colleagues, causing some privilege errors, so the use of Docker is prohibited.
When developers have to manage multiple services, having a Go language version of the Supervisor is a great help to the SRE team, so they don’t need to consider the Python version.
Installation method
You can download the corresponding OS version from the Release page, or you can compile it yourself if you are a GO developer.
Put supervisord
in the /usr/local/bin
directory. By default, the executable reads the supervisor.conf
configuration file, which can be read by -c
or automatically from the directory below
- $CWD/supervisord.conf
- $CWD/etc/supervisord.conf
- /etc/supervisord.conf
- /etc/supervisor/supervisord.conf (since Supervisor 3.3.0)
- ../etc/supervisord.conf (Relative to the executable)
- ../supervisord.conf (Relative to the executable)
Usage
Create or open the supervisor.conf
file
One of them is inet_http_server
which is a simple management interface to see the status of the configured process. The web interface is very simple, but useful.
Process can be started or suspended through the web interface, and this page can be protected by username
and password
. Next, see how the Process is set up:
|
|
One thing to note here is the stopsignal
setting. If you don’t set this item, and the process has a Graceful Shutdown, then the program will not end as you expect. Therefore, this option must be added. The related code can be found here. The default is to use syscall.SIGKILL
to force the program to shutdown.
p.Signal(syscall.SIGKILL, killasgroup)
|
|
In addition to the web interface, you can also use the CLI to see the status of all processes.
|
|
Supervisord also integrates with Prometheus monitoring, and SRE can get the related monitoring data underneath through http://localhost:9001/metrics
.
|
|
Finally, if you want to use the Supervisord
tool in Docker as well, you can copy the binary directly from the official image via COPY
.
Summary
At present, the whole ecology tends to be containerized, but this old management method, there are still various situations, with the Go language version, greatly reducing the team’s time to deal with the environment, it is recommended to use the Go version to integrate the Container internal, or in the non-Docker environment management.