安装Supervisor

easy_install supervisor

生成默认配置文件

echo_supervisord_conf > /etc/supervisord.conf

生成的配置文件默认使用/tmp文件,会被系统清理掉,需将所有使用/tmp/目录的路径改为/var/run/目录

; Sample supervisor config file.
;
; For more information on the config file, please see:
; http://supervisord.org/configuration.html
;
; Notes:
; - Shell expansion ("~" or "$HOME") is not supported. Environment
; variables can be expanded using this syntax: "%(ENV_HOME)s".
; - Quotes around values are not supported, except in the case of
; the environment= options as shown below.
; - Comments must have a leading space: "a=b ;comment" not "a=b;comment".
; - Command will be truncated if it looks like a config file comment, e.g.
; "command=bash -c 'foo ; bar'" will truncate to "command=bash -c 'foo ". [unix_http_server]
file=/var/run/supervisor.sock ; the path to the socket file
;chmod= ; socket file mode (default )
;chown=nobody:nogroup ; socket file uid:gid owner
;username=user ; default is no username (open server)
;password= ; default is no password (open server) [inet_http_server] ; inet (TCP) server disabled by default
port=*: ; ip_address:port specifier, *:port for all iface
username=user ; default is no username (open server)
password= ; default is no password (open server) [supervisord]
logfile=/var/log/supervisor.log ; main log file; default $CWD/supervisord.log
logfile_maxbytes=50MB ; max main logfile bytes b4 rotation; default 50MB
logfile_backups= ; # of main logfile backups; means none, default
loglevel=info ; log level; default info; others: debug,warn,trace
pidfile=/var/run/supervisor.pid ; supervisord pidfile; default supervisord.pid
nodaemon=false ; start in foreground if true; default false
minfds= ; min. avail startup file descriptors; default
minprocs= ; min. avail process descriptors;default
;umask= ; process file creation umask; default
;user=chrism ; default is current user, required if root
;identifier=supervisor ; supervisord identifier, default is 'supervisor'
;directory=/tmp ; default is not to cd during start
;nocleanup=true ; don't clean up tempfiles at start; default false
;childlogdir=/tmp ; 'AUTO' child log dir, default $TEMP
;environment=KEY="value" ; key value pairs to add to environment
;strip_ansi=false ; strip ansi escape codes in logs; def. false ; The rpcinterface:supervisor 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:x] sections. [rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface ; The supervisorctl section configures how supervisorctl will connect to
; supervisord. configure it match the settings in either the unix_http_server
; or inet_http_server section. [supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket
;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket
;username=chris ; should be same as in [*_http_server] if set
;password= ; should be same as in [*_http_server] if set
;prompt=mysupervisor ; cmd line prompt (default "supervisor")
;history_file=~/.sc_history ; use readline history if available ; The sample program section below shows all possible program subsection values.
; Create one or more 'real' program: sections to be able to control them under
; supervisor. ;[program:theprogramname]
;command=/bin/cat ; the program (relative uses PATH, can take args)
;process_name=%(program_name)s ; process_name expr (default %(program_name)s)
;numprocs= ; number of processes copies to start (def )
;directory=/tmp ; directory to cwd to before exec (def no cwd)
;umask= ; umask for process (default None)
;priority= ; the relative start priority (default )
;autostart=true ; start at supervisord start (default: true)
;startsecs= ; # of secs prog must stay up to be running (def. )
;startretries= ; max # of serial start failures when starting (default )
;autorestart=unexpected ; when to restart if exited after running (def: unexpected)
;exitcodes=, ; 'expected' exit codes used with autorestart (default ,)
;stopsignal=QUIT ; signal used to kill process (default TERM)
;stopwaitsecs= ; max num secs to wait b4 SIGKILL (default )
;stopasgroup=false ; send stop signal to the UNIX process group (default false)
;killasgroup=false ; SIGKILL the UNIX process group (def false)
;user=chrism ; setuid to this UNIX account to run the program
;redirect_stderr=true ; redirect proc stderr to stdout (default false)
;stdout_logfile=/a/path ; stdout log path, NONE for none; default AUTO
;stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
;stdout_logfile_backups= ; # of stdout logfile backups ( means none, default )
;stdout_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default )
;stdout_events_enabled=false ; emit events on stdout writes (default false)
;stderr_logfile=/a/path ; stderr log path, NONE for none; default AUTO
;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
;stderr_logfile_backups= ; # of stderr logfile backups ( means none, default )
;stderr_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default )
;stderr_events_enabled=false ; emit events on stderr writes (default false)
;environment=A="",B="" ; process environment additions (def no adds)
;serverurl=AUTO ; override serverurl computation (childutils) ; The sample eventlistener section below shows all possible eventlistener
; subsection values. Create one or more 'real' eventlistener: sections to be
; able to handle event notifications sent by supervisord. ;[eventlistener:theeventlistenername]
;command=/bin/eventlistener ; the program (relative uses PATH, can take args)
;process_name=%(program_name)s ; process_name expr (default %(program_name)s)
;numprocs= ; number of processes copies to start (def )
;events=EVENT ; event notif. types to subscribe to (req'd)
;buffer_size= ; event buffer queue size (default )
;directory=/tmp ; directory to cwd to before exec (def no cwd)
;umask= ; umask for process (default None)
;priority=- ; the relative start priority (default -)
;autostart=true ; start at supervisord start (default: true)
;startsecs= ; # of secs prog must stay up to be running (def. )
;startretries= ; max # of serial start failures when starting (default )
;autorestart=unexpected ; autorestart if exited after running (def: unexpected)
;exitcodes=, ; 'expected' exit codes used with autorestart (default ,)
;stopsignal=QUIT ; signal used to kill process (default TERM)
;stopwaitsecs= ; max num secs to wait b4 SIGKILL (default )
;stopasgroup=false ; send stop signal to the UNIX process group (default false)
;killasgroup=false ; SIGKILL the UNIX process group (def false)
;user=chrism ; setuid to this UNIX account to run the program
;redirect_stderr=false ; redirect_stderr=true is not allowed for eventlisteners
;stdout_logfile=/a/path ; stdout log path, NONE for none; default AUTO
;stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
;stdout_logfile_backups= ; # of stdout logfile backups ( means none, default )
;stdout_events_enabled=false ; emit events on stdout writes (default false)
;stderr_logfile=/a/path ; stderr log path, NONE for none; default AUTO
;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
;stderr_logfile_backups= ; # of stderr logfile backups ( means none, default )
;stderr_events_enabled=false ; emit events on stderr writes (default false)
;environment=A="",B="" ; process environment additions
;serverurl=AUTO ; override serverurl computation (childutils) ; The sample group section below shows all possible group values. Create one
; or more 'real' group: sections to create "heterogeneous" process groups. ;[group:thegroupname]
;programs=progname1,progname2 ; each refers to 'x' in [program:x] definitions
;priority= ; the relative start priority (default ) ; 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 = relative/directory/*.ini [program:CentOSWebApp]
command=dotnet CentOSWebApp.dll ; 运行程序的命令
directory=/home/app/app1/ ; 执行前要不要先cd到目录去,一般不用
autorestart = true ; 程序异常退出后自动重启
autostart=true ; 随着supervisord的启动而启动
startretries = 10 ; 启动失败自动重试次数,默认是 3
numprocs=1 ; 启动几个进程
stderr_logfile=/var/log/CentOSWebApp.err.log ; 错误日志文件
stdout_logfile=/var/log/CentOSWebApp.out.log ; 输出日志文件
environment=ASPNETCORE_ENVIRONMENT=Production ; 进程环境变量
user=root ; 进程执行的用户身份
stopsignal=KILL ; 用来杀死进程的
stopsignal=INT

守护单个program的内容一般如下:

[program:CentOSWebApp]
command=dotnet CentOSWebApp.dll ; 运行程序的命令
directory=/home/app/app1/ ; 执行前要不要先cd到目录去,一般不用
autorestart = true ; 程序异常退出后自动重启
autostart=true ; 随着supervisord的启动而启动
startretries = 10 ; 启动失败自动重试次数,默认是 3
numprocs=1 ; 启动几个进程
stderr_logfile=/var/log/CentOSWebApp.err.log ; 错误日志文件
stdout_logfile=/var/log/CentOSWebApp.out.log ; 输出日志文件
environment=ASPNETCORE_ENVIRONMENT=Production ; 进程环境变量
user=root ; 进程执行的用户身份
stopsignal=KILL ; 用来杀死进程的
stopsignal=INT

启动supervisord,查看是否生效

supervisord -c/etc/supervisord.conf

如果服务已启动,修改配置文件可用“supervisorctl reload”命令来使其生效

supervisorctl reload

配置Supervisor开机启动

新建一个“supervisord.service”文件

#supervisord service for systemd (CentOS 7.0+)
[Unit]
Description=Supervisor daemon [Service]
Type=forking
ExecStart=/usr/bin/supervisord -c/etc/supervisord.conf
ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown
ExecReload=/usr/bin/supervisorctl $OPTIONS reload
KillMode=process
Restart=on-failure
RestartSec=42s [Install]
WantedBy=multi-user.target

将文件拷贝至:“/usr/lib/systemd/system/”

执行命令:systemctl enable supervisord

执行命令:systemctl is-enabled supervisord #来验证是否为开机启动

centos通过Supervisor配置.net core守护进程的更多相关文章

  1. Supervisor 为服务创建守护进程

    今天需要再服务上部署一个.net 方面的项目:当时开启服务的命令只能在前台执行:使用nohub CMD &等放在后台开启服务都会宕机:所以搜寻了Supervisor 这个解决办法,为服务创建守 ...

  2. centos系统supervisor配置

    supervisor用来管理非daemon程序!将自动转换为daemon程序 安装: yum install supervisor 配置: 默认配置文件路径: /etc/supervisord.con ...

  3. Supervisor安装与配置(非守护进程管理工具)

    http://blog.csdn.net/xyang81/article/details/51555473

  4. 守护进程与Supervisor

    博客链接:http://www.cnblogs.com/zhenghongxin/p/8676565.html 消息队列处理后台任务带来的问题 在系统稍微大些的时候,我们经常会用到消息队列(实现的方式 ...

  5. supervisor配置与应用

    1.简介 supervisor 是一款基于Python的进程管理工具,可以很方便的管理服务器上部署的应用程序.supervisor的功能如下: a. 启动.重启.关闭包括但不限于python进程. b ...

  6. Linux之守护进程

    一.守护进程概述 在linux或者unix操作系统中在系统的引导的时候会开启很多服务,这些服务就叫做守护进 程.为了增加灵活性,root可以选择系统开启的模式,这些模式叫做运行级别,每一种运行级别以一 ...

  7. Linux 的进程组、会话、守护进程

    一.进程组ID 每个进程都属于一个进程组.每个进程组有一个领头进程.进程组是一个或多个进程的集合,通常它们与一组作业相关联,可以接受来自同一终端的各种信号.每个进程组都有唯一的进程组ID(整数,也可以 ...

  8. Linux企业级项目实践之网络爬虫(6)——将程序设计成为守护进程

    在linux或者unix操作系统中在系统的引导的时候会开启很多服务,这些服务就叫做守护进程.为了增加灵活性,root可以选择系统开启的模式,这些模式叫做运行级别,每一种运行级别以一定的方式配置系统. ...

  9. linux守护进程编写实践

    主要参考:http://colding.bokee.com/5277082.html (实例程序是参考这的) http://wbwk2005.blog.51cto.com/2215231/400260 ...

随机推荐

  1. Linux知识扩展二:lsof命令

    转:https://www.cnblogs.com/the-study-of-linux/p/5501593.html 1. lsof :list open file 显示linux下打开的文件信息. ...

  2. python实现FTP服务器

    https://www.cnblogs.com/huangxm/p/6274645.html

  3. VirtualBox 克隆后 IP 地址相同(DHCP 分配),如何变更MAC以获取不同的IP?

    由于需要做实验需要两个相同环境的虚拟机,在linux下使用virtualbox最小化安装centos6.0,并克隆了一个相同的,联网模式为桥接,修改配置文件之后重启网络发现二者的网络信息相同,所获取的 ...

  4. mysql的innodb和myisam的区别和应用场景

    1. 区别: (1)事务处理: MyISAM是非事务安全型的,而InnoDB是事务安全型的(支持事务处理等高级处理): (2)锁机制不同: MyISAM是表级锁,而InnoDB是行级锁: (3)sel ...

  5. PHP-预定义函数访问数据库

    (1)复习:自定义函数 (2)调用PHP预定义的函数——访问MySQL数据库 1.函数的基础概念   定义一个简单的函数: function  函数名( ){ #函数主体 }  调用/运行一次函数: ...

  6. 在datasnap 中使用unidac 访问数据(服务器端)

    从delphi 6 开始,datasnap 作为delphi 自带的多层框架,一直更新到最新的delphi 10.3 .同时逐步增加了很多新的功能 ,比如支持REST 调用,支持 IIS ,apach ...

  7. A - ACboy needs your help again!

    ACboy was kidnapped!! he miss his mother very much and is very scare now.You can't image how dark th ...

  8. VIP之CSC

    Color Space Converter II(CSC)   不同的色彩空间用于不同的设备.如RGB一般用于电脑显示器,YCbCr一般用于数字电视,IP还支持最小和最大的保护带[个人理解,这里的保护 ...

  9. Django同步数据库(/manage.py makemigrations) 报错

    新起了环境,创建models.py 内容,想要同步到数据库,执行以下操作时 报错: ./manage.py makemigrations ./manage.py migrate *(第一个步骤为在该项 ...

  10. freeRTOS与裸机程序相比有什么区别??

    FreeRTOS命名及变量规则 初学FreeRTOS的用户对其变量和函数的命名比较迷惑,    FreeRTOS的核心源代码遵从MISRA编码标准指南,关于MISRA编码标准,可以查看文章https: ...