python supervisor 日志_[web部署] supervisor日志-配置为服务

本文介绍了如何在CentOS7上将Supervisor配置为服务,包括将其移动到`/etc/init.d/`目录并设置开机启动。此外,还详细阐述了如何整合Supervisor与Flask的日志,包括日志输出的控制和配置选项。通过调整配置,可以实现日志的集中管理和清理,以及在不同运行模式下的日志记录策略。
摘要由CSDN通过智能技术生成

1.将supervisor配置成服务&&开机自启

配置supervisor为服务:

0.将supervisord文件移动到/etc/init.d/目录下

cp supervisord /etc/init.d/

配置开机启动:

1.使用chkconfig管理supervisor服务:

chkconfig --add supervisord

2.设置开机运行supervisor服务

chkconfig supervisord on

3.注意,配置服务脚本可执行权限

chmod 755 /etc/init.d/supervisord

服务命令:service supervisord start/stop/restart/status

其他:

centos7上,由于python3安装位置不同,故需要更改supervisord文件中的PREFIX变量(即python3位置)

如果flask以debug运行,则supervisor下flask会有两个进程,debug关闭后是正常的一个

#!/bin/bash

#

# supervisord This scripts turns supervisord on

#

# Author: Mike McGrath (based off yumupdatesd)

# Jason Koppe adjusted to read sysconfig,

# use supervisord tools to start/stop, conditionally wait

# for child processes to shutdown, and startup later

# Mikhail Mingalev Merged

# redhat-init-jkoppe and redhat-sysconfig-jkoppe, and

# made the script "simple customizable".

# Brendan Maguire Added OPTIONS to

# SUPERVISORCTL status call

#

# chkconfig: 345 83 04

#

# description: supervisor is a process control utility. It has a web based

# xmlrpc interface as well as a few other nifty features.

# Script was originally written by Jason Koppe .

#

# source function library

. /etc/rc.d/init.d/functions

set -a

PREFIX=/usr/local/python3

SUPERVISORD=$PREFIX/bin/supervisord

SUPERVISORCTL=$PREFIX/bin/supervisorctl

PIDFILE=/var/run/supervisord.pid

LOCKFILE=/var/lock/subsys/supervisord

OPTIONS="-c /home/python/estateQuery/estate_query_nolog/supervisor/supervisord.conf"

# unset this variable if you don't care to wait for child processes to shutdown before removing the $LOCKFILE-lock

WAIT_FOR_SUBPROCESSES=yes

# remove this if you manage number of open files in some other fashion

ulimit -n 96000

RETVAL=0

running_pid()

{

# Check if a given process pid's cmdline matches a given name

pid=$1

name=$2

[ -z "$pid" ] && return 1

[ ! -d /proc/$pid ] && return 1

(cat /proc/$pid/cmdline | tr "\000" "\n"|grep -q $name) || return 1

return 0

}

running()

{

# Check if the process is running looking at /proc

# (works for all users)

# No pidfile, probably no daemon present

[ ! -f "$PIDFILE" ] && return 1

# Obtain the pid and check it against the binary name

pid=`cat $PIDFILE`

running_pid $pid $SUPERVISORD || return 1

return 0

}

start() {

echo "Starting supervisord: "

if [ -e $PIDFILE ]; then

echo "ALREADY STARTED"

return 1

fi

# start supervisord with options from sysconfig (stuff like -c)

$SUPERVISORD $OPTIONS

# show initial startup status

$SUPERVISORCTL $OPTIONS status

# only create the subsyslock if we created the PIDFILE

[ -e $PIDFILE ] && touch $LOCKFILE

}

stop() {

echo -n "Stopping supervisord: "

$SUPERVISORCTL $OPTIONS shutdown

if [ -n "$WAIT_FOR_SUBPROCESSES" ]; then

echo "Waiting roughly 60 seconds for $PIDFILE to be removed after child processes exit"

for sleep in 2 2 2 2 4 4 4 4 8 8 8 8 last; do

if [ ! -e $PIDFILE ] ; then

echo "Supervisord exited as expected in under $total_sleep seconds"

break

else

if [[ $sleep -eq "last" ]] ; then

ech

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值