zoukankan      html  css  js  c++  java
  • Ubuntu 安装和使用 Supervisor(进程管理)

    原文:Ubuntu 安装和使用 Supervisor(进程管理) - 田园里的蟋蟀 - 博客园 (cnblogs.com)

    服务器版本 Ubuntu 16.04 LTS。

    Supervisor 是一个用 Python 写的进程管理工具,可以很方便的对进程进行启动、停止、重启等操作。

    安装命令:

    $ apt-get install supervisor
    

    安装成功后,会在/etc/supervisor目录下,生成supervisord.conf配置文件。

    你也可以使用echo_supervisord_conf > supervisord.conf命令,生成默认的配置文件(不建议,内容比较多)。

    supervisord.conf示例配置:

    ; supervisor config file
    
    [unix_http_server]
    file=/var/run/supervisor.sock   ; (the path to the socket file)
    chmod=0700                       ; sockef file mode (default 0700)
    
    [supervisord]
    logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
    pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
    childlogdir=/var/log/supervisor            ; ('AUTO' child log dir, default $TEMP)
    
    ; the below section must remain in the config file for RPC
    ; (supervisorctl/web interface) to work, additional interfaces may be
    ; added by defining them in separate rpcinterface: sections
    [rpcinterface:supervisor]
    supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
    
    [supervisorctl]
    serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL  for a unix socket
    
    ; The [include] section can just contain the "files" setting.  This
    ; setting can list multiple files (separated by whitespace or
    ; newlines).  It can also contain wildcards.  The filenames are
    ; interpreted as relative to this file.  Included files *cannot*
    ; include files themselves.
    
    [include]
    files = /etc/supervisor/conf.d/*.conf
    

    进程配置会读取/etc/supervisor/conf.d目录下的*.conf配置文件,我们在此目录下创建一个hwapp.conf进程配置文件:

    [program:hwapp]
    directory=/root/wwwroot/hwapp/publish
    command=dotnet hwapp.dll
    autostart=true
    autorestart=true
    startretries=10
    redirect_stderr=true
    stdout_logfile=/root/wwwroot/hwapp/hwapp.log
    environment=ASPNETCORE_ENVIRONMENT="Development"
    

    需要注意的是,如果不是root账号,需要对这些目录进行权限设置,要不然会报一些错误(一定要在 root 账号下进行配置,要不然一系列权限引起的问题)。

    $ sudo chmod 777 /var/run
    $ sudo chmod 777 /etc/supervisor
    

    接着就可以启动 Supervisord 了:

    $ supervisord
    

    supervisorctl 常用命令:

    命令说明
    supervisorctl stop program_name 停止某个进程
    supervisorctl start program_name 启动某个进程
    supervisorctl restart program_name 重启某个进程
    supervisorctl stop all 停止全部进程
    supervisorctl reload 载入最新的配置文件,停止原有进程并按新的配置启动、管理所有进程
    supervisorctl update 根据最新的配置文件,启动新配置或有改动的进程,配置没有改动的进程不会受影响而重启
  • 相关阅读:
    【转】什么是5G?居然有人用漫画把它讲得如此接地气!
    【转】Centos下编译升级安装Boost
    【转】SSH穿越跳板机:一条命令跨越跳板机直接登陆远程计算机
    部署JupyterLab和pyalgotrade搭建web策略回测环境
    [转]Linux中python3.6+ipython+Jupyter Notebook环境
    环境命令备忘
    [转]微软商店 打开就显示无法加载该页面 代码0x80131500?
    [转]Centos 7 安装部署 GitLab 服务器
    [转]本文采用all-in-one(一体化的)安装OpenShift
    [转]Linux编译和安装boost库
  • 原文地址:https://www.cnblogs.com/zhang1f/p/15771872.html
Copyright © 2011-2022 走看看