创建systemd服务和自动创建环境
作者:互联网
代码:
#!/bin/bash
workdir=`cd "$(dirname "$0")";pwd`
venv_dir=venv
tuna=https://pypi.tuna.tsinghua.edu.cn/simple
azkaban=/usr/lib/systemd/system/azkaban.service
if ! [ -x "$(command -v python3)" ]; then echo "There is no python3." exit 1; fi
if ! [ -x "$(command -v pip3)" ]; then echo "There is no pip3." exit 1; fi
cd $workdir
# 创建虚拟环境。
if ! [ -d $venv ]; then
if ! $(python -c "import virtualenv"); then pip3 install -i $tuna virtualenv ; fi
fi
virtualenv venv
source venv/bin/activate
pip install -i $tuna -r requirements.txt && deactivate
systemctl status azkaban &>/dev/null
if [ $? -eq 0 ]; then systemctl stop azkaban; fi
cat > $azkaban << EOF
[Unit]
Description=Azkaban Python Api
After=syslog.target
[Service]
User=root
Group=root
WorkingDirectory=$workdir
# ExecStartPre=source $workdir/venv/bin/activate
ExecStart=$workdir/venv/bin/python3 server.py
# ExecStopPost=deactivate
Restart=always
StandardError=syslog
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl start azkaban
标签:virtualenv,systemd,venv,pip3,创建,azkaban,自动,fi,tuna 来源: https://www.cnblogs.com/linga/p/15792340.html