创建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
作者: 咕咚!
出处: https://www.cnblogs.com/linga/
关于作者:专注虚拟化,运维开发,RPA,Rust,Go,Python!
本文版权归作者和博客园共有,禁止*.csdn.net转载,禁止以盈利为目的的转载,转载文章,但未经作者同意必须保留此段声明,且在文章页面明显位置给出, 原文链接 如有问题, 可邮件(oldsixa@163.com)咨询.