jenkins结合supervisor进行python程序发布后的自动重启
jenkins结合supervisor进行python程序发布后的自动重启 项目背景:
通过jenkins发布kvaccount.chinasoft.com站点的python服务端程序,业务部门同事需要每次发布完成须后自动重启python服务端 具体执行中遇到的问题:
代码的目录是apache的属主权限,通过jenkins远程调用脚本,强制关闭服务进程,再次启动进程,发现程序能正常重启,但是会夯住,导致jenkins发布job没法结束,想到supervisor都能没有tty的情况下管理程序,于是安装supervisor进行进程的管理 脚本如下:
直接在终端下可以正常重启程序,在jenkins程序调用的时候就失效了,导致程序夯住 #---------------------------------------------
[root@:/data/www/vhosts/kvaccount.chinasoft.com/httpdocs/Source]# cat restart_kvaccount.sh
#!/bin/bash
#
# kill fastcgi.py
source /etc/profile
py_num=`ps -ef|grep fastcgi.py|grep -v grep|wc -l`
if [ $py_num -ge ];then
ps -ef|grep fastcgi.py|grep -v grep|awk '{print $2}'|xargs kill -
fi
# start it
#su apache -c "cd /data/www/vhosts/kvaccount.chinasoft.com/httpdocs/Source && nohup python3 fastcgi.py > /dev/null &"
cd /data/www/vhosts/kvaccount.chinasoft.com/httpdocs/Source && nohup python3 fastcgi.py > /dev/null & exit
#--------------------------------------------- .安装supervisor
pip3 install supervisor cp /usr/local/python373/bin/supervisorctl /usr/bin/
cp /usr/local/python373/bin/supervisord /usr/bin/ .添加配置 mkdir -p /etc/supervisor/conf.d # 主配置supervisord.conf [root@srv3:/etc/supervisor/conf.d]# cat /etc/supervisor/supervisord.conf
; 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=/tmp/supervisor.sock ; the path to the socket file
file=/etc/supervisor/conf.d/supervisor.sock ; the path to the socket file
chmod= ; socket file mode (default )
chown=apache:users ; 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=127.0.0.1: ; 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=/tmp/supervisord.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=/tmp/supervisord.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:///tmp/supervisor.sock ; use a unix:// URL for a unix socket
serverurl=unix:///etc/supervisor/conf.d/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 = conf.d/*.conf # 程序的守护程序配置
[root@srv3:/etc/supervisor/conf.d]# cat service-worker.conf
[program:chinasoft-account]
process_name=%(program_name)s_%(process_num)02d
command=/usr/local/bin/python3 /data/www/vhosts/kvaccount.chinasoft.com/httpdocs/Source/fastcgi.py
autostart=true
autorestart=true
user=apache
numprocs=1
numprocs_start=1
redirect_stderr=true
stdout_logfile=/tmp/chinasoft-account.log 3.启动supervisor程序
chown -R apache.users /etc/supervisor
# 启动supervisor
/usr/local/bin/python3 /usr/bin/supervisord -c /etc/supervisor/supervisord.conf -u apache 4.发布程序apache账号的ssh方式进行重启python程序脚本 # 发布代码后自动重启python的shell脚本
[root@srv3:/etc/supervisor/conf.d]# cat /data/www/vhosts/kvaccount.chinasoft.com/httpdocs/Source/restart_kvaccount.sh
#!/bin/bash
#
# kill fastcgi.py
#!/bin/sh
source /etc/profile /usr/bin/supervisorctl restart chinasoft-account:* # python服务端相关程序和配置 [root@srv3:/data/www/vhosts/kvaccount.chinasoft.com/httpdocs/Source]# cat fastcgi.py
from app import app
from flup.server.fcgi import WSGIServer if __name__ == '__main__':
WSGIServer(app,bindAddress=('127.0.0.1', 8008)).run() [root@srv3:/data/www/vhosts/kvaccount.chinasoft.com/httpdocs/Source]# cat /usr/local/nginx/conf/vhost.d/kvaccount.chinasoft.com.conf
server {
listen 80;
server_name kvaccount.chinasoft.com;
access_log on;
access_log /data/www/logs/nginx_log/access/kvaccount.chinasoft.com_access.log main ;
error_log /data/www/logs/nginx_log/error/kvaccount.chinasoft.com_error.log ;
root /data/www/vhosts/kvaccount.chinasoft.com/httpdocs/Source;
index index.html index.shtml index.php; #location / {
# #include uwsgi_params;
# #uwsgi_pass 127.0.0.1:8008;
#} location / {
# 指定 fastcgi 的主机和端口
fastcgi_pass 127.0.0.1:8008;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_pass_header Authorization;
fastcgi_intercept_errors off;
} location ^~ /logs
{
deny all;
} } server {
listen 443;
ssl on; ssl_certificate cert2016/chinasoft_com.crt;
ssl_certificate_key cert2016/chinasoft_com.key;
ssl_dhparam cert2016/dh_2048.pem; ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:!AES128-GCM-SHA256:!AES256-GCM-SHA384:!AES128-SHA256:!AES256-SHA256:!AES128-SHA:!AES256-SHA:AES:!CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA"; ssl_prefer_server_ciphers on; #ssl_stapling on;
#ssl_stapling_verify on; server_name kvaccount.chinasoft.com ;
access_log on;
access_log /data/www/logs/nginx_log/access/kvaccount.chinasoft.com_access.log main ;
error_log /data/www/logs/nginx_log/error/kvaccount.chinasoft.com_error.log ; root /data/www/vhosts/kvaccount.chinasoft.com/httpdocs/Source;
index index.html index.shtml index.php ;
error_page 404 403 /404.html; #location / {
# #include uwsgi_params;
# #uwsgi_pass 127.0.0.1:8008;
#} location / {
# 指定 fastcgi 的主机和端口
fastcgi_pass 127.0.0.1:8008;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_pass_header Authorization;
fastcgi_intercept_errors off;
} if ($http_user_agent ~ Ezooms) {
return 403;
} location ^~ /logs
{
deny all;
} }
jenkins结合supervisor进行python程序发布后的自动重启的更多相关文章
- [VS2008] Debug版本程序发布后 由于应用程序的配置不正确,应用程序未能启动,重新安装应用程序可能会纠正这个问题
转自VC错误:http://www.vcerror.com/?p=59 问题描述: [VS2008] 版本程序发布后,运行程序弹出错误框: 由于应用程序的配置不正确,应用程序未能启动,重新安装应用程序 ...
- VS2010 使用时选择代码或双击时出错,点击窗口按钮后VS自动重启问题
VS2010 使用时选择代码或双击时出错崩溃,点击窗口按钮后VS自动重启问题 下载补丁,打上补丁之后,重启电脑,解决了问题. WindowsXP的下载地址:Windows XP 更新程序 (KB971 ...
- 微信小程序发布新版本时自动提示用户更新
如图,当小程序发布新的版本后,用户如果之前访问过该小程序,通过已打开的小程序进入(未手动删除),则会弹出这个提示,提醒用户更新新的版本.用户点击确定就可以自动重启更新,点击取消则关闭弹窗,不再更新. ...
- Web程序发布后显示个性化图标
采用Tomcat发布程序后,浏览器上默认显示程序的图标是Tomcat图标.如下图所示: 需要显示自己个性化的图标,比如,这里显示一个图标. 只需要如下三步设置即可. 将制作的ico图标放在程序的根目录 ...
- Qt开发MySQL程序发布后出现"Driver not loaded"的问题
1.安装qt的显示界面程序 2.安装mysql-server 3.给系统增加mysql-server的环境C:\Program Files\MySQL\MySQL Server 5.7\bin 4.将 ...
- 如何打开asp.net中的出错提示?在程序发布后
答案:修改其中的一个配置节点,<customErrors mode="On"/>
- IIS7程序发布后 之 报图表处理程序配置 [c:\TempImageFiles\] 中的临时目录无效
把.net4.0的ASP.NET网站布置在IIS7上,原本开发时一切ok,图形都能够出来,但是一旦部署到iis上,再访问的话, 错误问题:图表处理程序配置 [c:\TempImageFiles\] 中 ...
- android双进程守护,让程序崩溃后一定可以重启
由于我们做的是机器人上的软件,而机器人是24小时不间断服务的,这就要求我们的软件不能退出到系统桌面.当然最好是能够做到程序能够不卡顿,不崩溃,自己不退出.由于我们引用了很多第三方的开发包,也不能保证他 ...
- node.js之nodemon 代码热更新 修改代码后服务器自动重启
1.安装nodemon: npm install -g nodemon //全局安装 npm install nodemon --save //局部安装 2.在项目根目录下创建 nodemon.jso ...
随机推荐
- InvenSense 美国公司
InvenSense为智能型运动处理方案的先驱.全球业界的领导厂商,驱动了运动感测人机接口在消费性电子产品上的应用.公司提供的集成电路(IC)整合了运动传感器-陀螺仪以及相对应的软件,有别于其他厂商, ...
- 适用于在线服务的A/B测试方法论
适用于在线服务的A/B测试方法论 简介: 这篇文章旨在介绍适用于为在线服务进行A/B测试(A/B Test)的方法论.中文网络中目前还缺乏全面的入门级介绍. 我将首先讨论在线服务业进行A/B测试所考虑 ...
- 《hello-world》第九次团队作业:【Beta】Scrum meeting 2
项目 内容 这个作业属于哪个课程 2016级计算机科学与工程学院软件工程(西北师范大学) 这个作业的要求在哪里 实验十三 团队作业9:Beta冲刺与团队项目验收 团队名称 <hello--wor ...
- #define的一个小技巧
/* atof example: sine calculator */ #include <stdio.h> /* printf, fgets */ #include <stdlib ...
- spark如何划分DAG视图
spark根据宽依赖进行DAG视图的划分. 1.窄依赖:每个父RDD的partition 最多被一个子RDD的 partition使用. 窄依赖分为两类:第一类是一对一的依赖关系,在Spark中用On ...
- Arthas使用指南
Arthas 能为你做什么? 这个类从哪个 jar 包加载的?为什么会报各种类相关的 Exception? 我改的代码为什么没有执行到?难道是我没 commit?分支搞错了? 遇到问题无法在预发 de ...
- CF1185F Two Pizzas 状压
你发现 pizza 种类数不会很多,状压一下就可以了 code: #include <bits/stdc++.h> #define M 11 #define N 100005 #defin ...
- 洛谷 P1638 逛画展 题解
P1638 逛画展 题目描述 博览馆正在展出由世上最佳的 M 位画家所画的图画. wangjy想到博览馆去看这几位大师的作品. 可是,那里的博览馆有一个很奇怪的规定,就是在购买门票时必须说明两个数字, ...
- [SDOI2010][BZOJ 1925]地精部落
Description 传说很久以前,大地上居住着一种神秘的生物:地精. 地精喜欢住在连绵不绝的山脉中.具体地说,一座长度为 N 的山脉 H可分 为从左到右的 N 段,每段有一个独一无二的高度 Hi, ...
- OSPF基本详解