sudo cp install-laravel-supervisor.sh /usr/local/bin/lsp
sudo chmod +x /usr/local/bin/lsp
在 laravel
项目跟目录 执行:
sudo lsp [work-name]
#!/bin/bash | |
# Author: Jaeger <[email protected]> | |
fileName=$1; | |
# CentOS下目录改为:/etc/supervisord.d | |
confBasePath="/etc/supervisor/conf.d/" | |
# CentOS下文件后缀改为:.ini | |
confPath=${confBasePath}"$fileName.conf" | |
function add() | |
{ | |
laravelPath=`pwd`; | |
echo 'check supervisor...' | |
#type supervisorctl > /dev/null || (sudo apt update && sudo apt install supervisor -y) | |
conf="[program:$fileName] \nprocess_name=%(program_name)s_%(process_num)02d \ncommand=php $laravelPath/artisan queue:work --sleep=3 --tries=3 \nautostart=true \nautorestart=true \nuser=nobody \nnumprocs=2 \nredirect_stderr=true \nstdout_logfile=$laravelPath/storage/logs/worker.log" | |
echo "out conf:$confPath" | |
sudo echo -e $conf>$confPath; | |
echo 'start work....' | |
sudo supervisorctl reread | |
sudo supervisorctl update | |
sudo supervisorctl start $fileName:* | |
status | |
} | |
function delete() | |
{ | |
echo "delete:$confPath" | |
sudo supervisorctl stop $fileName:* | |
sudo rm $confPath; | |
sudo supervisorctl reread | |
sudo supervisorctl update | |
status | |
} | |
function list() | |
{ | |
path=$confBasePath | |
cd $path | |
echo -e "\n" | |
for filename in `ls` | |
do | |
echo $(basename $filename .conf) | |
done | |
echo -e "\n" | |
} | |
function status() | |
{ | |
echo -e "\n ----------run status---------- \n" | |
sudo supervisorctl status | |
echo -e "\n" | |
} | |
function restart() | |
{ | |
sudo supervisorctl restart $fileName:* | |
} | |
function option() | |
{ | |
echo "选择操作:" | |
select selected in '列出conf' '添加conf' '删除conf' '运行状态' '重启任务' '退出';do | |
case $selected in | |
'列出conf') | |
list | |
break | |
;; | |
'添加conf') | |
add | |
break | |
;; | |
'删除conf') | |
delete | |
break | |
;; | |
'运行状态') | |
status | |
break | |
;; | |
'重启任务') | |
restart | |
break | |
;; | |
'退出')exit;; | |
esac | |
done; | |
option; | |
} | |
option |