Last active
October 3, 2018 17:04
-
-
Save AndreiTelteu/28c3747f59b63d9e4361a195ea02c49d to your computer and use it in GitHub Desktop.
A startup script for swooletw/laravel-swoole, in two versions, one old init.d way, and a way better one using supervisor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# /etc/init.d/swoole-prod | |
# | |
# Example of init script for UNIX daemon | |
# | |
# chkconfig: 2345 20 80 | |
# description: Example of UNIX daemon | |
### BEGIN INIT INFO | |
# Provides: swoole-prod | |
# Required-Start: $rsyslog | |
# Required-Stop: | |
# Should-Start: | |
# Should-Stop: | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: start and stop example of daemon | |
# Description: Example of UNIX daemon | |
### END INIT INFO | |
# Source function library. | |
. /etc/rc.d/init.d/functions | |
prog="swoole-prod" | |
app="/usr/local/bin/ea-php72 /home/iorderapp/public_html/artisan swoole:http start" | |
pid_file="/home/iorderapp/public_html/storage/logs/swoole_http.pid" | |
lock_file="/home/iorderapp/public_html/storage/logs/swoole_http.lock" | |
log_file="/home/iorderapp/public_html/swoole-prod.log" | |
proguser="iorderapp" | |
start() { | |
[ -x $exec ] || exit 5 | |
echo -n $"Starting $prog: " | |
daemon --user $proguser $app | |
RETVAL=$? | |
[ $RETVAL -eq 0 ] && touch $lock_file | |
echo | |
return $RETVAL | |
} | |
stop() { | |
echo -n $"Stopping $prog: " | |
killproc -p ${pid_file} | |
RETVAL=$? | |
echo | |
[ $RETVAL -eq 0 ] && rm -f $lock_file | |
return $RETVAL | |
} | |
restart() { | |
stop | |
start | |
} | |
reload() { | |
restart | |
RETVAL=$? | |
echo | |
return $RETVAL | |
} | |
force_reload() { | |
restart | |
} | |
rh_status() { | |
status -p ${pid_file} | |
} | |
rh_status_q() { | |
rh_status >/dev/null 2>&1 | |
} | |
case "$1" in | |
start) | |
rh_status_q && exit 0 | |
$1 | |
;; | |
stop) | |
rh_status_q || exit 0 | |
$1 | |
;; | |
restart) | |
$1 | |
;; | |
reload) | |
rh_status_q || exit 7 | |
$1 | |
;; | |
force-reload) | |
force_reload | |
;; | |
status) | |
rh_status | |
;; | |
condrestart|try-restart) | |
rh_status_q || exit 0 | |
restart | |
;; | |
*) | |
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}" | |
exit 2 | |
esac | |
exit $? |
Installed and working way better.
Config for laravel swoole here:
[program:swoole-prod]
directory=/home/iorderapp/public_html/
command=/usr/local/bin/ea-php72 /home/iorderapp/public_html/artisan swoole:http start
user=iorderapp
autostart=true
autorestart=true
stdout_logfile=/home/iorderapp/public_html/swoole-prod.log
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
maybe a better solution
http://jeromejaglale.com/doc/centos/install_supervisor_for_beanstalkd_and_laravel_queues
https://pkrai.wordpress.com/2016/06/19/laravel-queues-with-supervisor/