You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2022/05/20 08:18:24 UTC
[apisix] branch master updated: feat(ops): check process running with posix.signal insteadof lsof (#7006)
This is an automated email from the ASF dual-hosted git repository.
spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push:
new 1a6f1b8e1 feat(ops): check process running with posix.signal insteadof lsof (#7006)
1a6f1b8e1 is described below
commit 1a6f1b8e18edc6a16b69af715ff2cc53eba4139a
Author: kwanhur <hu...@163.com>
AuthorDate: Fri May 20 16:18:17 2022 +0800
feat(ops): check process running with posix.signal insteadof lsof (#7006)
Signed-off-by: kwanhur <hu...@163.com>
Co-authored-by: 罗泽轩 <sp...@gmail.com>
---
apisix/cli/ops.lua | 23 +++++++++++++++--------
t/cli/test_main.sh | 24 ++++++++++++++++++++++++
2 files changed, 39 insertions(+), 8 deletions(-)
diff --git a/apisix/cli/ops.lua b/apisix/cli/ops.lua
index ae38a9dd5..f72ea42cb 100644
--- a/apisix/cli/ops.lua
+++ b/apisix/cli/ops.lua
@@ -25,6 +25,8 @@ local profile = require("apisix.core.profile")
local template = require("resty.template")
local argparse = require("argparse")
local pl_path = require("pl.path")
+local signal = require("posix.signal")
+local errno = require("posix.errno")
local stderr = io.stderr
local ipairs = ipairs
@@ -729,15 +731,20 @@ local function start(env, ...)
local pid = util.read_file(pid_path)
pid = tonumber(pid)
if pid then
- local lsof_cmd = "lsof -p " .. pid
- local res, err = util.execute_cmd(lsof_cmd)
- if not (res and res == "") then
- if not res then
- print(err)
- else
- print("APISIX is running...")
- end
+ if pid <= 0 then
+ print("invalid pid")
+ return
+ end
+
+ local signone = 0
+ local ok, err, err_no = signal.kill(pid, signone)
+ if ok then
+ print("APISIX is running...")
+ return
+ -- no such process
+ elseif err_no ~= errno.ESRCH then
+ print(err)
return
end
diff --git a/t/cli/test_main.sh b/t/cli/test_main.sh
index 88d01ccd4..128e9426f 100755
--- a/t/cli/test_main.sh
+++ b/t/cli/test_main.sh
@@ -706,6 +706,30 @@ fi
./bin/apisix stop
echo "pass: ignore stale nginx.pid"
+# check no corresponding process
+make run
+oldpid=$(< logs/nginx.pid)
+make stop
+sleep 0.5
+echo $oldpid > logs/nginx.pid
+out=$(make run || true)
+if ! echo "$out" | grep "nginx.pid exists but there's no corresponding process with pid"; then
+ echo "failed: should find no corresponding process"
+ exit 1
+fi
+make stop
+echo "pass: no corresponding process"
+
+# check running when run repeatedly
+out=$(make run; make run || true)
+if ! echo "$out" | grep "APISIX is running"; then
+ echo "failed: should find APISIX running"
+ exit 1
+fi
+
+make stop
+echo "pass: check APISIX running"
+
# check the keepalive related parameter settings in the upstream
git checkout conf/config.yaml