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"
CLK_TCK = 100
PID_FILE_PATH = "/run/app/pid".freeze
PROC_UPTIME_PATH = "/proc/uptime".freeze
SECONDS_PER_YEAR = 31_556_952
@ -109,7 +108,7 @@ end
class TickTock
def initialize
@pid = master_pid
@pid = ppid
@procfs_f = format "/proc/%s/stat", @pid
puts @pid
end
@ -178,9 +177,22 @@ class Sleep
end
end
def master_pid
pid_s = File.read PID_FILE_PATH
Integer pid_s.strip
def ppid
pid = Process.pid
# 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
def system_uptime
@ -350,19 +362,19 @@ get "/snowflake" do
end
post "/quit" do
Process.kill("TERM", master_pid)
Process.kill("TERM", ppid)
nil
end
post "/halt" do
Process.kill("QUIT", master_pid)
Process.kill("QUIT", ppid)
nil
end
get "/pid" do
pretty = params.key? :pretty
jsonify({puma: master_pid, pid: Process.pid}, pretty:)
jsonify({ppid: ppid, pid: Process.pid}, pretty:)
end
get "/token" do

View File

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