Notes on installing and deploying supervisor in docker

Time:2021-8-4

Recently, workman has been used in the work. The running environment is the basic image built by alpine. It is planned to install supervisor to automatically run and manage the workman process after the container is started

  • Install Supervisor

    apk add --no-cache supervisor

Notes on installing and deploying supervisor in docker

This error indicates that the supervisor server has not been started

  • Configuration management process

    The default path of the supervisor configuration file is / etc / supervisor.conf. In order to avoid turning the configuration file into a big dumpling, it is better to configure our customized configuration file independently. After checking the / etc / supervisor.conf file, you can find that the configuration will load the configuration files with all ini suffixes of Supervisor. D / *. Ini in the same level directory

Notes on installing and deploying supervisor in docker

  • Configuration customization file

    The preliminary configuration is as follows:
    [supervisord]
    logfile=/webser/logs/gatewayworker/supervisord.log
    pidfile=/var/supervisord.pid
    [program:gateway_worker]
    command=/usr/bin/php /webser/www/start.php start -d
    numprocs=1
    autostart=true
    autorestart=true
    startsecs=3
    stdout_logfile=/webser/logs/gatewayworker/supervisord_out.log
    stderr_logfile=/webser/logs/gatewayworker/supervisord_err.log

    Of course, we need to configure the log file to map it out, so as to avoid the loss of restart. The problem can not be investigated in the future. If the PID file is not configured, it will be generated by default under the same level of supervisor.conf. Of course, we don’t want it to pollute the etc directory. Gateway worker can only start one process in the container without port conflict.

Notes on installing and deploying supervisor in docker

As can be seen from the above figure, after the supervisor starts the server, the gateway is found_ The worker process status is fatal. Through log troubleshooting, the problem of port occupation is reported, indicating that it is restarted many times. Why?

It is learned on the Internet that supervisor will run the process in the configuration in the background, so the command can no longer be configured to run in the background.

command=/usr/bin/php /webser/www/start.php start -dRemove the “- D” of this command and see the result

Notes on installing and deploying supervisor in docker

It can be seen from the figure that it has been started normally. Note that after modifying the configuration, use docker compose to restart, otherwise you will encounter another problem. Let’s talk about it below.

As above, if the configuration file is modified, an unexpected situation will occur

Notes on installing and deploying supervisor in docker

You can see that there are duplicate processes. What’s going on?

The reason is that when reload reloads the configuration, the supervisor only closes the main process of the command in the configuration, and the sub process generated in the command does not stop, resulting in a lonely process (kill the – 9 process number manually here). It’s ok if there are lonely processes after multiple restarts.

In fact, supervisor supports configuration to kill child processes. If configured

stopasgroup=true
killasgroup=true

Notes on installing and deploying supervisor in docker

Look, there is no orphan process. I’m relieved.

  • Configure supervisor to automatically start the service after the container is started

    Previously, in order to suspend the container, it was used together with the docker compose configuration filecommand: "tail -f", it must be our supervisor command now.

    command: "/usr/bin/supervisord -c /etc/supervisord.conf"Unfortunately, the result is not as I expected. The container always exits as soon as it starts. What’s the situation? Later, we changed the scheme to add a startup script start.sh, which is executed when the container is startedcommand: "bash /var/start.sh", the script is to start the supervisor service, but it doesn’t work as I want.

    Wonder! In my impression, I have seen using the supervisor command configuration to suspend containers. Why not? What’s wrong?

    Calm down and search before getting to another point. The supervisor service is started by the background process by default. When we use docker compose again, we need to configure it to run in the foreground to make it play the role of suspending the container.

    How to operate? To configure Supervisornodaemon=falseChange tonodaemon=true, make the supervisor run in the previous mode to maintain the suspended state of the container.
  • The final configuration is like this
    [supervisord]
    logfile=/webser/logs/gatewayworker/supervisord.log
    pidfile=/var/supervisord.pid
    nodaemon=true
    [program:gateway_worker]
    command=/usr/bin/php /webser/www/start.php start
    numprocs=1
    autostart=true
    autorestart=true
    startsecs=3
    stopasgroup=true
    killasgroup=true
    stdout_logfile=/webser/logs/gatewayworker/supervisord_out.log
    stderr_logfile=/webser/logs/gatewayworker/supervisord_err.log

This work adoptsCC agreement, reprint must indicate the author and the link to this article

Snowflakes floating

Recommended Today

Ubuntu 20.04 — Hello minikube!

Article background Minikube is a tool that can run kubernetes locally. Minikube can run a single node kubernetes cluster on personal computers (including windows, MacOS and Linux PCs) for kubernetes trial or daily developmentAll you need is docker (or similar compatible) container or virtual machine environment. Kubernetes only needs one command:minikube start . More similar […]