linux supervisor 定时,Linux:supervisor命令的使用

典型的supervisor.conf配置如下:(配置文件的注释用分号开头)

; supervisor config file

[unix_http_server] ; supervisor与supervisorctl的通讯

file=/var/run/supervisor.sock ; (the path to the socket file) should match serverurl in section supervisorctl

chmod=0700 ; sockef file mode (default 0700)

[supervisord] ; 必须有,用来配置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] ; 必须有,用于配置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 = /path/to/*.conf # other configuration files you want to include

[program:api4c] ;应用程序的配置

command=/path/to/python/env/bin/gunicorn -w 1 -b 0.0.0.0:8888 wsgi:application ; 执行你的命令,不能是用于启动守护进程,因为supervisor就是用来作为守护进程的

directory=/home/ubuntu/4c-entry/api4c ; chdir to here before command run

startsecs=0 ;

stopwaitsecs=0 ;

autostart=true ; supervisord启动的时候自动运行

autorestart=true ; 当程序中断的时候是否重启 stop,true,false,unexpected

stdout_logfile=/path/to/logfile.log ; 必须已经存在

stderr_logfile=/path/to/std/err/log/for4c.err

上面是一个基本的服务,用于管理一个服务进程,包含几个必要的section:supervisord、supervisorctl、program:your_program_name、rpcinterface:supervisor、include。

这几个是一定要配置的,缺少supervisord和supervisorctl和rpcinterface:supervisor会报错,include是可选的,如果你没有引入其他的配置文件的话。

关于supervisord和supervisorctl的通讯方式有两种:一种是通过sock来传输,也就是unix_http_server的配置,另一种是inet_http_server,通过http进行通讯,详细的设置可以参考supervisor的配置文档。

supervisor的常用命令:

supervisord -c supervisor.conf                             通过配置文件启动supervisor

supervisorctl -c supervisor.conf status                    察看supervisor的状态

supervisorctl -c supervisor.conf reload                    重新载入 配置文件  更新后可以选择重新载入

supervisorctl -c supervisor.conf start [all] |  [appname]     启动指定/所有 supervisor管理的程序进程

supervisorctl -c supervisor.conf stop [all] | [appname]

命令使用实例:

配置项:

[program:hello]

command=python /home/smallfish/hello.py

autorstart=true

stdout_logfile=/home/smallfish/hello.log

命令

shell> sudo /etc/init.d/supervisor start   -- 启动supervisor服务

shell> sudo supervisorctl status hello     -- 获取hello服务的状态,因为是autorstart,这里已经启动了 hello  RUNNING    pid 1159, uptime 0:20:32

shell> sudo supervisorctl stop hello       -- 停止hello服务 hello: stopped

shell> sudo supervisorctl stop hello       -- 再次停止hello,会有错误信息 hello: ERROR (not running)

shell> sudo supervisorctl start hello      -- 启动hello服务 hello: started

常用的配置项:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用Linux Supervisor,你可以按照以下步骤进行配置和操作: 1. 安装Supervisor使用适合你Linux发行版的软件包管理器(如apt、yum等)安装Supervisor。例如,在Ubuntu上,可以使用以下命令进行安装: ```shell sudo apt-get install supervisor ``` 2. 配置SupervisorSupervisor的配置文件位于`/etc/supervisor/conf.d/`目录下。你可以在该目录中创建一个以`.conf`为后缀的配置文件来配置你想要监控的进程。例如,创建一个名为`myapp.conf`的配置文件: ```shell sudo nano /etc/supervisor/conf.d/myapp.conf ``` 在配置文件中,你需要指定进程的命令、运行参数、工作目录等信息。以下是一个示例配置文件的内容: ``` [program:myapp] command=/path/to/myapp directory=/path/to/myapp/directory autostart=true autorestart=true user=myuser ``` 3. 更新配置:保存并关闭配置文件后,使用以下命令更新Supervisor的配置: ```shell sudo supervisorctl reread sudo supervisorctl update ``` 4. 操作进程:使用`supervisorctl`命令来管理和监控进程。例如,启动进程: ```shell sudo supervisorctl start myapp ``` 停止进程: ```shell sudo supervisorctl stop myapp ``` 重启进程: ```shell sudo supervisorctl restart myapp ``` 查看进程状态: ```shell sudo supervisorctl status ``` 这些是基本的Supervisor使用步骤。你可以根据自己的需求进行进一步的配置和操作,例如设置日志、限制进程资源等。请确保在使用Supervisor之前,你已经了解和熟悉相关的配置选项和命令

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值