目的:
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
4.修改權限
命令:
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] Swoft\SwoftApplication:setSystemAlias(417) Project path: @base=/root/myproject/Swoft
2020/05/05-15:04:47 [INFO] Swoft\SwoftApplication:setSystemAlias(418) Set alias @app=@base/app
2020/05/05-15:04:47 [INFO] Swoft\SwoftApplication:setSystemAlias(419) Set alias @config=@base/config
2020/05/05-15:04:47 [INFO] Swoft\SwoftApplication:setSystemAlias(420) Set alias @runtime=@base/runtime
2020/05/05-15:04:47 [INFO] Swoft\Processor\EnvProcessor:handle(60) Env file(/root/myproject/Swoft/.env) is loaded
2020/05/05-15:04:48 [INFO] Swoft\Processor\AnnotationProcessor:handle(45) Annotations is scanned(autoloader 36, annotation 472, parser 93)
2020/05/05-15:04:48 [INFO] Swoft\Processor\BeanProcessor:handle(53) Bean is initialized(singleton 330, prototype 79, definition 50)
2020/05/05-15:04:48 [INFO] Swoft\Processor\BeanProcessor:handle(57) Config path is /root/myproject/Swoft/config
2020/05/05-15:04:48 [INFO] Swoft\Processor\BeanProcessor:handle(62) Config env is not setting
2020/05/05-15:04:48 [INFO] Swoft\Processor\EventProcessor:handle(35) Event manager initialized(66 listener, 4 subscriber)
2020/05/05-15:04:48 [INFO] Swoft\WebSocket\Server\Listener\AppInitCompleteListener:handle(44) WebSocket server route registered(module 3, message command 14)
2020/05/05-15:04:48 [INFO] Swoft\Tcp\Server\Listener\AppInitCompleteListener:handle(45) Tcp server route registered(routes 4)
2020/05/05-15:04:48 [INFO] Swoft\Error\Listener\AppInitCompleteListener:handle(34) Error manager init completed(4 type, 5 handler, 5 exception)
2020/05/05-15:04:48 [INFO] Swoft\Processor\ConsoleProcessor: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] Swoft\Server\Server:startSwoole(491) Swoole\Runtime::enableCoroutine
2020/05/05-15:04:48 [INFO] Swoft\Listener\BeforeStartListener:handle(27) Server extra info: pidFile @runtime/swoft.pid
2020/05/05-15:04:48 [INFO] Swoft\Listener\BeforeStartListener:handle(28) Registered swoole events:
start, shutdown, managerStart, managerStop, workerStart, workerStop, workerError, request, task, finish
Server start success (Master PID: 2594, Manager PID: 2600)
文件改變,自動重啓。