summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-04-05 23:34:14 +0800
committerruki <[email protected]>2022-04-05 23:34:14 +0800
commit0e44d2d07d75233b07856112f3bfa8a838c1e5c9 (patch)
tree6222465ae5dbe1937433c9ea84c888e843e9082c
parent934d15f424106a6426641f4fa067382b51978b45 (diff)
add pidfile for server
-rw-r--r--xmake/core/base/os.lua6
-rw-r--r--xmake/modules/private/service/server.lua18
-rw-r--r--xmake/modules/private/service/stop_service.lua4
3 files changed, 18 insertions, 10 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index cb6821d3d..823d3d009 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -975,25 +975,19 @@ end
-- get uid
function os.uid(...)
- -- get uid
os._UID = {}
if os._uid then
os._UID = os._uid(...) or {}
end
-
- -- ok?
return os._UID
end
-- get gid
function os.gid(...)
- -- get gid
os._GID = {}
if os._gid then
os._GID = os._gid(...) or {}
end
-
- -- ok?
return os._GID
end
diff --git a/xmake/modules/private/service/server.lua b/xmake/modules/private/service/server.lua
index d627076d7..a4ce80706 100644
--- a/xmake/modules/private/service/server.lua
+++ b/xmake/modules/private/service/server.lua
@@ -69,8 +69,7 @@ function server:runloop()
assert(self._HANDLER, "no handler found!")
-- ensure only one server process
- local lockfile = os.tmpfile(tostring(self)) .. ".lock"
- local lock = io.openlock(lockfile)
+ local lock = io.openlock(self:lockfile())
if not lock:trylock() then
raise("%s: has been started!", self)
end
@@ -98,6 +97,21 @@ function server:class()
return server
end
+-- get pid file
+function server:pidfile()
+ return path.join(self:workdir(), "server.pid")
+end
+
+-- get lock file
+function server:lockfile()
+ return path.join(self:workdir(), "server.lock")
+end
+
+-- get working directory
+function server:workdir()
+ return os.tmpfile(tostring(self)) .. ".dir"
+end
+
function server:__tostring()
return "<server>"
end
diff --git a/xmake/modules/private/service/stop_service.lua b/xmake/modules/private/service/stop_service.lua
index 723ca4416..6f444c4af 100644
--- a/xmake/modules/private/service/stop_service.lua
+++ b/xmake/modules/private/service/stop_service.lua
@@ -20,9 +20,9 @@
-- imports
import("core.base.option")
-import("private.service.service")
+import("private.service.remote_build_server")
function main()
- -- TODO
+ print(remote_build_server():workdir())
end