Skip to content

Instantly share code, notes, and snippets.

@jae-jae
Last active September 4, 2018 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jae-jae/1a5efa9239a9aa30baedbad88fd24496 to your computer and use it in GitHub Desktop.
Save jae-jae/1a5efa9239a9aa30baedbad88fd24496 to your computer and use it in GitHub Desktop.
laravel supervisor

install-laravel-supervisor

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 <JaegerCode@gmail.com>
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment