supervisor管理python程序

  1. 下载supervisor

      0 16:47:26 root@test,172.16.1.12:~ # yum -y install supervisor
    
  2. 配置supervisor

      0 16:49:51 root@test,172.16.1.12:~ # cp /etc/supervisord.conf{,.bak}
      0 16:50:14 root@test,172.16.1.12:~ # vim /etc/supervisord.conf
    [unix_http_server]
    file=/server/data/supervisord/supervisor.sock   ; the path to the socket file
    
    [supervisord]
    logfile=/server/logs/supervisord/supervisord.log ; main log file; default $CWD/supervisord.log
    logfile_maxbytes=50MB        ; max main logfile bytes b4 rotation; default 50MB
    logfile_backups=10           ; # of main logfile backups; 0 means none, default 10
    loglevel=info                ; log level; default info; others: debug,warn,trace
    pidfile=/server/data/supervisord/supervisord.pid ; supervisord pidfile; default supervisord.pid
    nodaemon=false               ; start in foreground if true; default false
    minfds=1024                  ; min. avail startup file descriptors; default 1024
    minprocs=200                 ; min. avail process descriptors;default 200
    
    [rpcinterface:supervisor]
    supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
    
    [supervisorctl]
    serverurl=unix:///server/data/supervisord/supervisor.sock ; use a unix:// URL  for a unix socket
    
    [include]
    files = /etc/supervisord.d/*.conf
    
  3. 启动supervisor

      0 16:52:09 root@test,172.16.1.12:~ # mkdir -p /server/data/supervisord /server/logs/supervisord
      0 16:53:04 root@test,172.16.1.12:~ # systemctl start supervisord.service 
      0 16:55:00 root@test,172.16.1.12:~ # systemctl enable supervisord.service
    
  4. 管理一个python程序。

      0 16:55:33 root@test,172.16.1.12:~ # vim /etc/supervisord.d/backend.conf
    [program:backend]
    
    directory=/datas/app/platform/backend
    command=/datas/app/platform/backend/venv/bin/python manage.py runserver 0.0.0.0:8000
    autorestart=true
    
  5. 加载配置自动启动。

      0 17:03:01 root@test,172.16.1.12:/etc/supervisord.d # supervisorctl reload
    Restarted supervisord
      0 17:03:06 root@test,172.16.1.12:/etc/supervisord.d # supervisorctl status
    backend                          RUNNING   pid 256117, uptime 0:00:02
    


写作不易,转载请注明出处,谢谢~~

posted @ 2021-09-23 10:51  loosenc  阅读(167)  评论(0编辑  收藏  举报