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 ...
随机推荐
- Kotlin继承与重写重要特性剖析
继续Kotlin的面向对象之旅. 继承: 在Java中我们知道除了final类不能被继承,其它的情况都是可以被继承的,而在Kotlin中的规则是这样的:“在Kotlin中,所有类在默认情况下都是无法被 ...
- 采集新浪新闻php插件
今天没事,就分享一个采集新浪新闻PHP插件接口,可用于火车头采集,比较简单,大家可以研究! 新浪新闻实时动态列表为:https://news.sina.com.cn/roll/?qq-pf-to=pc ...
- LINQ查询表达式(4) - LINQ Join联接
内部联接 按照关系数据库的说法,“内部联接”产生一个结果集,对于该结果集内第一个集合中的每个元素,只要在第二个集合中存在一个匹配元素,该元素就会出现一次. 如果第一个集合中的某个元素没有匹配元素,则它 ...
- maven项目重构-使用了mybatis generator插件
1.在worksapce下,dos窗口输入spring init -g=com.briup.apps -a=poll3 -d=mysql,mybatis,web poll3 2.下载依赖,cd到pol ...
- 使用笔记:TF辅助工具--tensorflow slim(TF-Slim)
如果抛开Keras,TensorLayer,tfLearn,tensroflow 能否写出简介的代码? 可以!slim这个模块是在16年新推出的,其主要目的是来做所谓的“代码瘦身” 一.简介 slim ...
- Python3.X下安装Scrapy
Python3.X下安装Scrapy (转载) 2017年08月09日 15:19:30 jingzhilie7908 阅读数:519 标签: python 相信很多同学对于爬虫需要安装Scrap ...
- 运算符的应用及流程控制if,switch语句
运算符的应用 1:赋值运算符 简单赋值运算符 例如var useName='tom';//简单赋值运算符 复合赋值运算符 a+=b;//相当于a=a+b; ...
- mongodb 副本集的主的选举
primary的选举依赖于各个实例的优先权重,默认权重都是1 复本集的主挑选权重最高的,权重一样的无法控制谁为主 设置各个实例的优先权重,挑选自己想要的实例为主,只有primary可以更改权重配置 c ...
- window的pid为4的system进程占用80端口的解决办法
1.taskkill /pid 4 /f 无法终止进程占用80端口的进程时,运行 net stop http(若是第一次运行不能终止所有服务,继续运行该命令)
- 土豆案例(display:none和block的应用)
利用display:none和display:blocks设置鼠标经过的一个效果. 注意的几个点:1.子绝父相定位 2.设置百分比宽高 3.播放按钮放用背景图做 4.a:hover .mask的写法 ...