swoft实现自动重启服务 转

目的:
1.上传代码后HTTP服务自动重启,不需要自己手动执行:php bin/swoft http:start
2.自动重启适用于开发调试阶段,因为不能再后台运行所以在线上环境的话还是要重启http服务

a.Swoft-cli
1.下载

wget https://github.com/swoft-cloud/swoft-cli/releases/download/{VERSION}/swoftcli.phar
注意:你需要替换 {VERSION} 部分为最新版本。

wget https://github.com/swoft-cloud/swoft-cli/releases/download/v0.2.0/swoftcli.phar

2.测试
命令:

php swoftcli.phar -V

结果:

Command line tool application for quick use swoft (Version: 0.1.6)
_____ ______ ________ ____
/ ___/ ______ / __/ /_ / ____/ / / _/
\__ | /| / / __ / /_/ __/ / / / / / /
___/ / |/ |/ / /_/ / __/ /_ / /___/ /____/ /
/____/|__/|__/\____/_/ \__/ \____/_____/___/

PHP: 7.2.30, Swoft: 2.0.8, Swoole: 4.5.0


3.文件转移到bin目录
命令:

mv swoftcli.phar /usr/local/bin/swoftcli

测试报错

swoftcli -V
-bash: /usr/local/bin/swoftcli: Permission denied


修改权限
命令:

chmod a+x /usr/local/bin/swoftcli

再次测试

swoftcli -V
️ Command line tool application for quick use swoft (Version: 0.1.6)
_____ ______ ________ ____
/ ___/ ______ / __/ /_ / ____/ / / _/
\__ | /| / / __ / /_/ __/ / / / / / /
___/ / |/ |/ / /_/ / __/ /_ / /___/ /____/ /
/____/|__/|__/\____/_/ \__/ \____/_____/___/

PHP: 7.2.30, Swoft: 2.0.8, Swoole: 4.5.0

b. 热重启
命令:

swoftcli run -c http:start
结果:

Work Information
current pid 2592
current dir /root/*****Swoft
php binFile /usr/l*******/bin/php
target path /root/*****/Swoft
watch dirs app, config
entry file /root/******/bin/swoft
execute cmd /usr/l********Swoft/bin/swoft http:start

Watched Directories
/root/******/Swoft/app
/root/*******/Swoft/config

2020/05/05-07:04:47 [SWOFTCLI] Start swoft server
2020/05/05-15:04:47 [INFO] SwoftSwoftApplication:setSystemAlias(417) Project path: @base=/root/myproject/Swoft
2020/05/05-15:04:47 [INFO] SwoftSwoftApplication:setSystemAlias(418) Set alias @app=@base/app
2020/05/05-15:04:47 [INFO] SwoftSwoftApplication:setSystemAlias(419) Set alias @config=@base/config
2020/05/05-15:04:47 [INFO] SwoftSwoftApplication:setSystemAlias(420) Set alias @runtime=@base/runtime
2020/05/05-15:04:47 [INFO] SwoftProcessorEnvProcessor:handle(60) Env file(/root/myproject/Swoft/.env) is loaded
2020/05/05-15:04:48 [INFO] SwoftProcessorAnnotationProcessor:handle(45) Annotations is scanned(autoloader 36, annotation 472, parser 93)
2020/05/05-15:04:48 [INFO] SwoftProcessorBeanProcessor:handle(53) Bean is initialized(singleton 330, prototype 79, definition 50)
2020/05/05-15:04:48 [INFO] SwoftProcessorBeanProcessor:handle(57) Config path is /root/myproject/Swoft/config
2020/05/05-15:04:48 [INFO] SwoftProcessorBeanProcessor:handle(62) Config env is not setting
2020/05/05-15:04:48 [INFO] SwoftProcessorEventProcessor:handle(35) Event manager initialized(66 listener, 4 subscriber)
2020/05/05-15:04:48 [INFO] SwoftWebSocketServerListenerAppInitCompleteListener:handle(44) WebSocket server route registered(module 3, message command 14)
2020/05/05-15:04:48 [INFO] SwoftTcpServerListenerAppInitCompleteListener:handle(45) Tcp server route registered(routes 4)
2020/05/05-15:04:48 [INFO] SwoftErrorListenerAppInitCompleteListener:handle(34) Error manager init completed(4 type, 5 handler, 5 exception)
2020/05/05-15:04:48 [INFO] SwoftProcessorConsoleProcessor:handle(36) Console command route registered (group 14, command 44)
____ _____ ____ __ ___ ___
/ __/ _____ / _/ /_ / __/______ ___ _ ___ _ _____ ____/ /__ |_ | / _
_ | |/|/ / _ / _/ __/ / _// __/ _ `/ ' / -_) |/|/ / _ / __/ '_/ / __/_/ // /
/___/|__,__/\___/_/ \__/ /_/ /_/ \_,_/_/_/_/\__/|__,__/\___/_/ /_/\_ /____(_)___/

SERVER INFORMATION(v2.0.9)
*******************************************************************************
* HTTP | Listen: 0.0.0.0:9502, Mode: Process, Worker: 6, Task worker: 12
*******************************************************************************

HTTP Server Start Success!
2020/05/05-15:04:48 [INFO] SwoftServerServer:startSwoole(491) SwooleRuntime::enableCoroutine
2020/05/05-15:04:48 [INFO] SwoftListenerBeforeStartListener:handle(27) Server extra info: pidFile @runtime/swoft.pid
2020/05/05-15:04:48 [INFO] SwoftListenerBeforeStartListener:handle(28) Registered swoole events:
start, shutdown, managerStart, managerStop, workerStart, workerStop, workerError, request, task, finish
Server start success (Master PID: 2594, Manager PID: 2600)


文件改变,自动重启。
————————————————
版权声明:本文为CSDN博主「MichaelGzy」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_42949954/java/article/details/105932710

原文地址:https://www.cnblogs.com/brady-wang/p/13277439.html