进程管理工具 supervisor 部署脚本-CentOS7.9
#! /bin/bash
pip3 -V
if [ $? -ne 0 ];then
echo " 没有python3环境,即将开始安装python3"
yum install python3 -y
if [ $? -eq 0 ];then
echo "已安装好python3"
pip3 -V
else
echo "python3 安装失败"
exit 1
fi
fi
echo "开始安装 supervisor"
pip3 install supervisor -i https://mirrors.aliyun.com/pypi/simple/
if [ $? -ne 0 ];then
echo " supervisor 安装失败"
exit 1
else
echo " supervisor 安装成功"
fi
echo "开始配置supervisor"
mkdir -p /etc/supervisor/conf.d/
echo_supervisord_conf > /etc/supervisor/supervisord.conf
echo "[include]" >> /etc/supervisor/supervisord.conf
echo "files = /etc/supervisor/conf.d/*.conf" >> /etc/supervisor/supervisord.conf
sed -i 's/\/tmp\/supervisor.sock/\/var\/run\/supervisor.sock/g;s/\/tmp\/supervisord.log/\/var\/log\/supervisord.log/g;s/\/tmp\/supervisord.pid/\/var\/run\/supervisord.pid/g' /etc/supervisor/supervisord.conf
if [ $? -ne 0 ];then
echo " 修改配置出现异常,请检查或手动修改配置文件"
fi
echo " 将supervisor 配置成服务"
touch /usr/lib/systemd/system/supervisord.service
cat >> /usr/lib/systemd/system/supervisord.service << EOF
[Unit]
Description=supervisor
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/bin/supervisord -c /etc/supervisor/supervisord.conf
ExecReload=/usr/local/bin/supervisorctl reload
ExecStop=/usr/local/bin/supervisorctl shutdown
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl start supervisord
systemctl enable supervisord