Compare commits

...

2 Commits

Author SHA1 Message Date
7831c5da16
/pid route should return JSON
All checks were successful
Gitea Actions Demo / lint (push) Successful in 50s
Gitea Actions Demo / test (push) Successful in 17s
Gitea Actions Demo / docker (push) Successful in 2m6s
2025-04-03 20:52:32 -05:00
8667d0571f
have Puma set the PID of the master process 2025-04-03 20:52:32 -05:00
2 changed files with 7 additions and 16 deletions

22
app.rb
View File

@ -117,7 +117,6 @@ class TickTock
def initialize
@pid = ppid
@procfs_f = format "/proc/%s/stat", @pid
puts @pid
end
def uptime
@ -185,20 +184,11 @@ class Sleep
end
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
pid = ENV.fetch "PUMA_PID", Process.pid
begin
Integer pid
rescue ArgumentError
-1
end
end
@ -384,7 +374,7 @@ post "/halt" do
nil
end
get "/pid" do
get "/pid", provides: "json" do
pretty = params.key? :pretty
jsonify({ppid: ppid, pid: Process.pid}, pretty:)

1
config/puma.rb Normal file
View File

@ -0,0 +1 @@
ENV["PUMA_PID"] = Process.pid.to_s