1 使用Systemd,建立*.service 文件的方式:
/etc/systemd/system目录下建立文件 test.service
通过.sh文件重启(.sh文件路径自定义)
[Unit]
Description=uwsgi-xxx-support
After=network.target
Before=nginx.service
[Service]
ExecStart=/usr/sbin/xxx.sh
ExecReload=/bin/kill -HUP ( ps -ep | grep uwsgi)
Type=forking
[Install]
WantedBy=multi-user.target
systemctl enable test.service
创建your.sh文件
创建后执行chmod +x /yourpwd/your.sh
要给.sh 文件执行权限
#!/bin/sh
venvwrap="virtualenvwrapper.sh"
python38=`/usr/bin/which python3.8`
VIRTUALENVWRAPPER_PYTHON=${python38}
export WORKON_HOME=/root/.virtualenvs
if [ $? -eq 0 ]; then
venvwrap=`/usr/bin/which $venvwrap`
source $venvwrap
fi
workon env
uwsgi --ini /yourpwd/uwsgi.ini &
要设置 VIRTUALENVWRAPPER_PYTHON,否则source ...../virtualenvwrapper.sh会报错,报找不到python
要export WORKON_HOME ,否则workon找不到虚拟环境
2 将your.sh脚本添加到启动文件中
vim /root/.bashrc
末尾添加
# your project run
if [ -f /yourpwd/your.sh ]; then
./yourpwd/your.sh
fi
如果./your.sh执行不了,改成bash /yourpwd/your.sh