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 ...
随机推荐
- linux系统编程之信号(一)
今天起,开始新的知识的学习,对于上个系列进程的学习还差一个理论上的总结,这个会下次补回来,以便通过实践之后,再用理论将其巩固一下,好了,话不多说,开始进入这个主题的学习----信号,很重要,但不是太容 ...
- 前端学习笔记--css案例
要实现的案例: 1.分析布局 2.划分文件结构: 3.编写css代码 * { padding: 0; margin: 0; } body { font-size: 16px; color: burly ...
- Java单个对象内存布局.md
我们在如何获取一个Java对象所占内存大小的文章中写了一个获取Java对象所占内存大小的工具类(ObjectSizeFetcher),那么接下来,我们使用这个工具类来看一下Java中各种类型的对象所占 ...
- RANSEC算法
移步:https://blog.csdn.net/u010128736/article/details/53422070 clc;clear;close all; %%%二维直线拟合 %%%生成随机数 ...
- 洛谷 P5640 【CSGRound2】逐梦者的初心 题解
每日一题 day33 打卡 Analysis 这道题太难♂了,居然才是蓝的. 每个位子和每种字符都是独立的,对每种字符都记录一下位子. 用f[i]=0 or 1 表示长度为ii的后缀可不可以,0表示可 ...
- IP地址与Mac地址绑定错误
有个application,有时候可以正常访问,有时候又返回404错误,百思不得其解.刚开始以为是文件夹权限问题,折腾了好久. 后来没在服务器上monitor到包,所以猜想是到了错误的mac地址,用a ...
- mysql 时区更改;5.7 弱口令
一.mysql 更改表名称: show databases; use 库名; show tables; rename table 旧表名 to 新表名: 示例: rename table old to ...
- SAM:后缀自动机
好文转载 luoguP3804 代码: /* 定义.对给定字符串s的后缀自动机是一个最小化确定有限状态自动机,它能够接收字符串s的所有后缀. 对给定字符串s的后缀自动机是一个最小化确定有限状态自动机, ...
- 《挑战30天C++入门极限》C++类的继承与多重继承的访问控制
C++类的继承与多重继承的访问控制 在前面的练习中我们一直在使用public的继承方式,即共有继承方式,对于protected和private继承方式,即保护继承与私有继承方式我们并没有讨论. ...
- ubuntu18.04 安装UHD+GNU Radio
参考链接: ubuntu16.04下安装uhd与gnuradio:https://blog.csdn.net/qq_37748396/article/details/80339366 GNU Radi ...