ICHARM
Centos设置swoole开机自动启动
Centos设置swoole开机自动启动

最近哀差闷的laravel项目接入了Swoole,使用的是LaravelS开源方案。启动swoole server只需要执行 php artisan laravels start  配合nginx做反向代理非常方便。但是每次重启都需要手动执行这个命令启动swoole server。于是哀差闷写了一个简单的shell脚本用来自动启动laravelS。

一、在 /etc/init.d 文件夹下创建名为laravels的脚本。复制下面的脚本内容。

#!/bin/sh
#
# Simple laravels init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

### BEGIN INIT INFO
# Provides:     	laravels
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    Laravel Swoole server
# Description:          Laravel Swoole server. See https://github.com/hhxsv5/laravel-s/blob/master/README-CN.md
### END INIT INFO

DIR=/Your laravel project path
PHP=/usr/share/php7/bin/php #php路径,不填全路径可能报错
EXEC=${DIR}/artisan
COMMAND=laravels

PIDFILE=${DIR}/storage/laravels.pid

case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
                echo "$PIDFILE exists, process is already running or crashed"
        else
                echo "Starting laravel swoole server..."
                $PHP $EXEC $COMMAND start
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                echo "Stopping ..."
                $PHP $EXEC $COMMAND stop
        fi
        ;;
    restart)
	echo "Restarting..."
	$PHP $EXEC $COMMAND restart
	;;
    reload)
	echo "Reloading all file..."
	$PHP $EXEC $COMMAND reload
	;;
    publish)
	echo "Publishing configure file..."
	$PHP $EXEC $COMMAND publish
	;;
    *)
        echo "Please use start|stop|restart|reload|publish as first argument"
        ;;
esace

二、修改上面脚本的DIR变量的值为laravel项目的根目录,保存。

三、为laravels添加可执行权限

 chmod +x laravels

四、加入开机启动

 chkconfig laravels on

五、使用servies管理laravels

 service laravels start|stop|restart|reload|publish

发表评论

textsms
account_circle
email

ICHARM

Centos设置swoole开机自动启动
最近哀差闷的laravel项目接入了Swoole,使用的是LaravelS开源方案。启动swoole server只需要执行 php artisan laravels start  配合nginx做反向代理非常方便。但是每次重启都需…
扫描二维码继续阅读
2018-08-11