create a new method for inferring the PPID
Some checks failed
Gitea Actions Demo / release-image (push) Blocked by required conditions
Gitea Actions Demo / lint (push) Successful in 2m34s
Gitea Actions Demo / test (push) Has been cancelled

This commit is contained in:
Ryan Cavicchioni 2025-03-24 11:16:03 -05:00
parent 8b094d64b1
commit 7883107bdf
Signed by: ryanc
SSH Key Fingerprint: SHA256:KbXiwUnZnHFwFtt3Bytd+F3FN9pPHn1Z1cxMIE1TPbg
2 changed files with 20 additions and 11 deletions

28
app.rb
View File

@ -28,7 +28,6 @@ DEFAULT_FLAKEY = 50
ENV_PREFIX = "KUBERNAUT" ENV_PREFIX = "KUBERNAUT"
CLK_TCK = 100 CLK_TCK = 100
PID_FILE_PATH = "/run/app/pid".freeze
PROC_UPTIME_PATH = "/proc/uptime".freeze PROC_UPTIME_PATH = "/proc/uptime".freeze
SECONDS_PER_YEAR = 31_556_952 SECONDS_PER_YEAR = 31_556_952
@ -109,7 +108,7 @@ end
class TickTock class TickTock
def initialize def initialize
@pid = master_pid @pid = ppid
@procfs_f = format "/proc/%s/stat", @pid @procfs_f = format "/proc/%s/stat", @pid
puts @pid puts @pid
end end
@ -178,9 +177,22 @@ class Sleep
end end
end end
def master_pid def ppid
pid_s = File.read PID_FILE_PATH pid = Process.pid
Integer pid_s.strip # self
ps = File.open "/proc/#{pid}/stat", &:readline
ps = ps.split(" ")
ppid = Integer(ps[3])
# ppid
ps = File.open "/proc/#{ppid}/stat", &:readline
ps = ps.split(" ")
if ps[1].include? "ruby"
ppid
else
pid
end
end end
def system_uptime def system_uptime
@ -350,19 +362,19 @@ get "/snowflake" do
end end
post "/quit" do post "/quit" do
Process.kill("TERM", master_pid) Process.kill("TERM", ppid)
nil nil
end end
post "/halt" do post "/halt" do
Process.kill("QUIT", master_pid) Process.kill("QUIT", ppid)
nil nil
end end
get "/pid" do get "/pid" do
pretty = params.key? :pretty pretty = params.key? :pretty
jsonify({puma: master_pid, pid: Process.pid}, pretty:) jsonify({ppid: ppid, pid: Process.pid}, pretty:)
end end
get "/token" do get "/token" do

View File

@ -1,3 +0,0 @@
# workers 3
pidfile "/run/app/pid"
preload_app!