Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Installation and use of supervisor

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "the installation and use of supervisor". In the daily operation, I believe that many people have doubts about the installation and use of supervisor. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "installation and use of supervisor". Next, please follow the editor to study!

I. installation

Source code installation

First download the latest supervisor installation package: https://pypi.python.org/pypi/supervisor, such as:

Cd / usr/local/srcwget https://pypi.python.org/packages/7b/17/88adf8cb25f80e2bc0d18e094fcd7ab300632ea00b601cbbbb84c2419eae/supervisor-3.3.2.tar.gztar-zxvf supervisor-3.3.2.tar.gzcd supervisor-3.3.2python setup.py install # Local python version is python2.7# python2.7 setup.py install # Local python version is above python3

II. Configuration

1. Generate configuration file

Echo_supervisord_conf > / etc/supervisord.conf

two。 Start

Supervisord-c / etc/supervisord.conf

Check to see if supervisord is running:

Ps aux | grep supervisord

3. Configuration

Open the configuration file

Vim / etc/supervisord.conf

At the bottom of the configuration file, configure include

[include] files=/etc/supervisor/*.conf # if you don't have a / etc/supervisor directory locally, please create it yourself

Use supervisor to manage the process, configured as follows:

Cd / etc/supervisorvim ossfs.conf # the file name here is customized

Add the following:

; set the name of the process. You need to use the process name [program:your_program_name] command=python server.py-- port=9000;numprocs=1 when using supervisorctl to manage the process. The default is 1 program_name processing% (program_name) s. The default is% (program_name) s, that is, xdirectory=/home/python/tornado_server in [program:x]. Switch to the working directory user=oxygen before executing command. Use the oxygen user to start the process; restart automatically when the program crashes, the number of restarts is limited, default is 3 times autorestart=true redirect_stderr=true; redirect output log stdout _ logfile = / var/log/supervisord/tornado_server.logloglevel=info

Here are the parameters to be configured for startup. Please customize and add them according to your project.

The supervisor configuration file has been changed and needs to be restarted. Run the following instructions:

Supervisorctl reload

The usage of 4.supervisorctl

Supervisord: start supervisorsupervisorctl reload: restart supervisorsupervisorctl status after modifying the configuration file: check the process status monitored by supervisor supervisorctl start process name: start the XXX process supervisorctl stop process name: stop the XXX process supervisorctl stop all: stop the whole process, note: start, restart, stop will not be loaded into the latest configuration file. Supervisorctl update: according to the latest configuration file, start processes with new configuration or changes, and processes with no changes in configuration will not be affected and restart

5. If you do not use the console to manage the process, but use the browser to manage it, how to configure it?

Open the configuration file

Vim / etc/supervisord.conf

Configure inet_http_server

[inet_http_server] port=127.0.0.1:9001; Server ipusername=xxx; Custom password=xxx; Custom

Third, set up boot boot

Vim / etc/init.d/supervisord

Add the following script

#! / bin/sh### BEGIN INIT INFO# Provides: supervisord# Required-Start: $remote_fs# Required-Stop: $remote_fs# Default-Start: 2 3 4 "Default-Stop: 0 1" Short-Description: Example initscript# Description: This file should be used to construct scripts to be# placed in/ etc/init.d.### END INIT INFO# Author: Dan MacKinlay # Based On instructions by Bertrand Mathieu# http://zebert.blogspot.com/2009/05/installing-django-solr-varnish-and.html# Do NOT "set-e" # PATH should only include / usr/* if it runs after the mountnfs.sh scriptPATH=/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:/bin:/usr/binDESC= "Description of the service" NAME=supervisordDAEMON=/usr/local/bin/supervisordDAEMON_ARGS= "- c / etc/supervisord.conf" # PIDFILE=/var/run / $NAME.pidPIDFILE=/tmp/$NAME.pidSCRIPTNAME=/etc/init.d/$NAME# Exit if the package is not installed [- x "$DAEMON"] | | exit Read configuration variable file if it is present [- r / etc/default/$NAME] & &. / etc/default/$NAME# Load the VERBOSE setting and other rcS variables. / lib/init/vars.sh# Define LSB log_* functions.# Depend on lsb-base (> = 3.0-6) to ensure that this file is present.. / lib/lsb/init-functions## Function that starts the daemon/service#do_start () {# Return # 0 if daemon has been started # 1 if daemon was already running # 2 if daemon could not be started start-stop-daemon-- start--quiet-- pidfile $PIDFILE-- exec $DAEMON-- test > / dev/null\ | return 1 start-stop-daemon-- start--quiet-- pidfile $PIDFILE-- exec $DAEMON-- $DAEMON_ARGS\ | | return 2 # Add code here If necessary, that waits for the process to be ready # to handle requests from services started subsequently which depend # on this one. As a last resort Sleep for some time.} # # Function that stops the daemon/service#do_stop () {# Return # 0 if daemon has been stopped # 1 if daemon was already stopped # 2 if daemon could not be stopped # other if a failure occurred start-stop-daemon-- stop--quiet-- retry=TERM/30/KILL/5-pidfile $PIDFILE-- name $NAME RETVAL= "$?" ["$RETVAL" = 2] & & return 2 # Wait For children to finish too if this is a daemon that forks # and if the daemon is only ever run from this initscript. # If the above conditions are not satisfied then add some other code # that waits for the process to drop all resources that could be # needed by services started subsequently. A last resort is to # sleep for some time. Start-stop-daemon-stop--quiet-oknodo-retry=0/30/KILL/5-exec $DAEMON ["$?" = 2] & & return 2 # Many daemons don't delete their pidfiles when they exit. Rm-f $PIDFILE return "$RETVAL"} # # Function that sends a SIGHUP to the daemon/service#do_reload () {# If the daemon can reload its configuration without # restarting (for example, when it is sent a SIGHUP), # then implement that here. # start-stop-daemon-- stop--signal 1-- quiet-- pidfile $PIDFILE-- name $NAME return 0} case "$1" in start) ["$VERBOSE" = no] & & log_daemon_msg "Starting $DESC"$NAME" do_start case "$?" In 0 | 1) ["$VERBOSE"! = no] & & log_end_msg 0;; 2) ["$VERBOSE"! = no] & & log_end_msg 1;; esac;; stop) ["$VERBOSE"! = no] & & log_daemon_msg "Stopping $DESC"$NAME" do_stop case "$?" In 0 | 1) ["$VERBOSE"! = no] & & log_end_msg 0;; 2) ["$VERBOSE"! = no] & & log_end_msg 1;; esac;; # reload | force-reload) # # If do_reload () is not implemented then leave this commented out # and leave 'force-reload' as an alias for' restart'. # # log_daemon_msg "Reloading $DESC"$NAME" # do_reload # log_end_msg $? #; restart | force-reload) # # If the "reload" option is implemented then remove the # 'force-reload' alias # log_daemon_msg "Restarting $DESC"$NAME" do_stop case "$?" In 0 | 1) do_start case "$?" In 0) log_end_msg 0;; 1) log_end_msg 1;; # Old process is still running *) log_end_msg 1;; # Failed to start esac;; *) # Failed to stop log_end_msg 1;; esac *) # echo "Usage: $SCRIPTNAME {start | stop | restart | reload | force-reload}" > & 2 echo "Usage: $SCRIPTNAME {start | stop | restart | force-reload}" > & 2 exit 3;; esac:# set the script to execute sudo chmod + x / etc/init.d/supervisord# and set sudo update-rc.d supervisord defaults# to boot automatically to try whether service supervisord stopservice supervisord start works properly

If you report an error: insserv: warning: script 'service' missing LSB tags and overrides, please execute:

Sudo apt-get remove insserv at this point, on the "installation and use of supervisor" study is over, I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report