Skip to content

Commit

Permalink
feat:support restart cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
bingcool committed Apr 21, 2024
1 parent 2df5e09 commit e7f7c81
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 35 deletions.
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,13 @@ define('APP_NAMES', [
]);
// 启动前处理,比如加载.env
$beforeFunc = function () {
try {
if (\Swoolefy\Core\SystemEnv::isDevEnv()) {
LoadEnv::load('192.168.25.53:8848','swoolefy','pwa-test','nacos','nacos');
}
}catch (\Throwable $throwable) {
}
};
//$beforeFunc = function () {
// try {
// \Test\LoadEnv::load('192.168.1.101:8848','swoolefy','test','nacos-test','123456');
// }catch (\Throwable $exception) {
//
// }
//};
include __DIR__.'/swoolefy';
Expand Down
2 changes: 1 addition & 1 deletion autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ public static function register(bool $prepend = false)
// include file
autoloader::register();
// include constants
include ROOT_PATH.'/Config/constants.php';
include APP_PATH.'/Config/constants.php';
5 changes: 3 additions & 2 deletions src/Cmd/BaseCmd.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,18 @@ protected function beforeInputOptions()
*/
protected function initCheck(InputInterface $input, OutputInterface $output)
{
$appName = $input->getArgument('app_name');
if (version_compare(phpversion(), '7.3.0', '<')) {
fmtPrintError("php version must >= 7.3.0, current php version = " . phpversion());
}

if (version_compare(swoole_version(), '4.8.5', '<')) {
fmtPrintError("the swoole version must >= 4.8.5, current swoole version = " . swoole_version());
}

if (function_exists('apc_clear_cache')) {
apc_clear_cache();
}

if (function_exists('opcache_reset')) {
opcache_reset();
}
Expand Down Expand Up @@ -277,7 +278,7 @@ protected function makeDirLogAndPid(array &$config)
}

if (!isset($config['app_conf'])) {
fmtPrintError(APP_NAME . "/Protocol/conf.php" . " must include app_conf file and set app_conf");
fmtPrintError(APP_NAME . '/Protocol/conf.php must include app_conf file and set app_conf');
exit(0);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Cmd/MonitorCmd.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$selfScript = $_SERVER['argv'][0];
$appName = $input->getArgument('app_name');
$pidFile = $this->getPidFile($appName);
$appName = $input->getArgument('app_name');
$pidFile = $this->getPidFile($appName);
// 人为执行stop命令后,会删除pidFile,防止监控不断重启进程。只有异常情况下的进程停止,pidFile会存在,不被删除,然后会监控判断是否需要重启
if (!is_file($pidFile)) {
fmtPrintError("Pid file={$pidFile} is not exist, please check server weather is running");
Expand Down
6 changes: 3 additions & 3 deletions src/Cmd/RestartCmd.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
$force = $input->getOption('force');
$lineValue = "";
if (empty($force)) {
if (!isWorkerService()) {
$lineValue = initConsoleStyleIo()->ask( "1、你确定 【重启】 应用【{$appName}】? (yes or no)");
} else {
if (SystemEnv::isWorkerService()) {
$lineValue = initConsoleStyleIo()->ask( "1、你确定 【重启】 workerService【" . WORKER_SERVICE_NAME . "】? (yes or no)");
} else {
$lineValue = initConsoleStyleIo()->ask( "1、你确定 【重启】 应用【{$appName}】? (yes or no)");
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Cmd/SendCmd.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
return 0;
}

$appName = $input->getArgument('app_name');
$appName = $input->getArgument('app_name');
$processName = getenv('name');
$action = getenv('action');
$msg = getenv('msg');
$action = getenv('action');
$msg = getenv('msg');
if (empty($msg)) {
$msg = '';
}
Expand Down
18 changes: 9 additions & 9 deletions src/Cmd/StopCmd.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@ protected function execute(InputInterface $input, OutputInterface $output)
$force = $input->getOption('force');
$lineValue = "";
if (empty($force)) {
if (!isWorkerService()) {
$lineValue = initConsoleStyleIo()->ask( "1、你确定停止应用【{$appName}】? (yes or no)");
if (SystemEnv::isWorkerService()) {
$lineValue = initConsoleStyleIo()->ask( "1、你确定 [停止] workerService【" . WORKER_SERVICE_NAME . "】? (yes or no)");
} else {
$lineValue = initConsoleStyleIo()->ask( "1、你确定停止workerService【" . WORKER_SERVICE_NAME . "】? (yes or no)");
$lineValue = initConsoleStyleIo()->ask( "1、你确定 [停止] 应用【{$appName}】? (yes or no)");
}
}

if (strtolower($lineValue) == 'yes' || $force) {
if (!isWorkerService()) {
$this->commonStop($appName);
} else {
if (SystemEnv::isWorkerService()) {
$this->workerStop($appName);
} else {
$this->commonStop($appName);
}
} else {
if (!isWorkerService()) {
fmtPrintInfo("\n你已放弃停止应用{$appName},应用继续running中");
if (SystemEnv::isWorkerService()) {
fmtPrintInfo(PHP_EOL."你已放弃停止workerService【" . WORKER_SERVICE_NAME . ",应用继续running中");
} else {
fmtPrintInfo("\n你已放弃停止workerService【" . WORKER_SERVICE_NAME . ",应用继续running中");
fmtPrintInfo(PHP_EOL."你已放弃停止应用{$appName},应用继续running中");
}
exit(0);
}
Expand Down
8 changes: 2 additions & 6 deletions src/Stubs/swag.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@
exit("【Error】missing source dir\n");
}

defined('ROOT_PATH') or define('ROOT_PATH', __DIR__);
// 启动目录
defined('START_DIR_ROOT') or define('START_DIR_ROOT', __DIR__);

// 启动目录
defined('START_DIR_ROOT') or define('START_DIR_ROOT', __DIR__);
// 应用父目录
defined('ROOT_PATH') or define('ROOT_PATH', __DIR__);
// 应用目录
defined('APP_PATH') or define('APP_PATH', __DIR__.'/'.ucfirst($_SERVER['argv'][2]));
// 应用目录(此处获取的$_SERVER['argv'][1])
defined('APP_PATH') or define('APP_PATH', __DIR__.'/'.ucfirst($_SERVER['argv'][1]));

registerNamespace(APP_PATH);

Expand Down

0 comments on commit e7f7c81

Please sign in to comment.