Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
8e9a37b477 | |||
7831c5da16 | |||
8667d0571f | |||
bb7f309b34 | |||
9b2d2f9522 | |||
a30c6d7cb8 | |||
20c34f3c76 | |||
dc9b8b7cc7 | |||
149b42825f | |||
2285def168 | |||
a83fa30cd4 |
56
app.rb
56
app.rb
@ -2,6 +2,7 @@ require "bundler/setup"
|
|||||||
require "sinatra"
|
require "sinatra"
|
||||||
require "sinatra/cookies"
|
require "sinatra/cookies"
|
||||||
require "sinatra/multi_route"
|
require "sinatra/multi_route"
|
||||||
|
require "sinatra/quiet_logger"
|
||||||
require "time"
|
require "time"
|
||||||
require "fileutils"
|
require "fileutils"
|
||||||
require "json"
|
require "json"
|
||||||
@ -20,7 +21,7 @@ $LOAD_PATH.unshift File.dirname(__FILE__) + "/lib"
|
|||||||
|
|
||||||
require "config"
|
require "config"
|
||||||
|
|
||||||
VERSION = "0.1.2"
|
VERSION = "0.1.4"
|
||||||
|
|
||||||
CHUNK_SIZE = 1024**2
|
CHUNK_SIZE = 1024**2
|
||||||
SESSION_SECRET_HEX_LENGTH = 64
|
SESSION_SECRET_HEX_LENGTH = 64
|
||||||
@ -52,9 +53,12 @@ DURATION_PARTS = [
|
|||||||
|
|
||||||
config = Config.new
|
config = Config.new
|
||||||
|
|
||||||
|
set :quiet_logger_prefixes, %w[livez readyz]
|
||||||
set :session_secret, config.session_secret.unwrap
|
set :session_secret, config.session_secret.unwrap
|
||||||
set :public_folder, __dir__ + "/static"
|
set :public_folder, __dir__ + "/static"
|
||||||
|
|
||||||
|
register Sinatra::QuietLogger
|
||||||
|
|
||||||
module Sinatra
|
module Sinatra
|
||||||
module RequestHeadersHelper
|
module RequestHeadersHelper
|
||||||
def req_headers
|
def req_headers
|
||||||
@ -113,7 +117,6 @@ class TickTock
|
|||||||
def initialize
|
def initialize
|
||||||
@pid = ppid
|
@pid = ppid
|
||||||
@procfs_f = format "/proc/%s/stat", @pid
|
@procfs_f = format "/proc/%s/stat", @pid
|
||||||
puts @pid
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def uptime
|
def uptime
|
||||||
@ -164,7 +167,7 @@ class Sleep
|
|||||||
include State
|
include State
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@file = "/dev/shm/sleep"
|
@file = "/dev/shm/sleepy"
|
||||||
end
|
end
|
||||||
|
|
||||||
def asleep?
|
def asleep?
|
||||||
@ -181,20 +184,11 @@ class Sleep
|
|||||||
end
|
end
|
||||||
|
|
||||||
def ppid
|
def ppid
|
||||||
pid = Process.pid
|
pid = ENV.fetch "PUMA_PID", Process.pid
|
||||||
# self
|
begin
|
||||||
ps = File.open "/proc/#{pid}/stat", &:readline
|
Integer pid
|
||||||
ps = ps.split(" ")
|
rescue ArgumentError
|
||||||
ppid = Integer(ps[3])
|
-1
|
||||||
|
|
||||||
# ppid
|
|
||||||
ps = File.open "/proc/#{ppid}/stat", &:readline
|
|
||||||
ps = ps.split(" ")
|
|
||||||
|
|
||||||
if ps[1].include? "ruby"
|
|
||||||
ppid
|
|
||||||
else
|
|
||||||
pid
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -232,9 +226,7 @@ end
|
|||||||
|
|
||||||
enable :sessions
|
enable :sessions
|
||||||
|
|
||||||
on_start do
|
puts "#{NAME} #{VERSION} staring, per aspera ad astra"
|
||||||
puts "#{NAME} #{VERSION} staring, per aspera ad astra"
|
|
||||||
end
|
|
||||||
|
|
||||||
configure do
|
configure do
|
||||||
mime_type :json, "application/json"
|
mime_type :json, "application/json"
|
||||||
@ -309,31 +301,31 @@ get "/headers", provides: "json" do
|
|||||||
jsonify h, pretty:
|
jsonify h, pretty:
|
||||||
end
|
end
|
||||||
|
|
||||||
get "/livez" do
|
get "/uptime", provides: "json" do
|
||||||
error 503 unless Health.instance.healthy?
|
|
||||||
|
|
||||||
return Health.instance.to_json if request.env["HTTP_ACCEPT"] == "application/json"
|
|
||||||
|
|
||||||
Health.instance.to_s
|
|
||||||
end
|
|
||||||
|
|
||||||
get "/livez/uptime" do
|
|
||||||
tt = TickTock.new
|
tt = TickTock.new
|
||||||
x = {started_at: tt.started_at, seconds: tt.uptime.to_i, human: human_time(tt.uptime.to_i)}
|
x = {started_at: tt.started_at, seconds: tt.uptime.to_i, human: human_time(tt.uptime.to_i)}
|
||||||
|
|
||||||
jsonify x
|
jsonify x
|
||||||
end
|
end
|
||||||
|
|
||||||
post "/livez/toggle" do
|
post "/api/livez/toggle" do
|
||||||
Health.instance.toggle
|
Health.instance.toggle
|
||||||
"ok\n"
|
"ok\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
post "/livez/sleep" do
|
post "/api/livez/sleep" do
|
||||||
Sleep.instance.toggle
|
Sleep.instance.toggle
|
||||||
"ok\n"
|
"ok\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get "/livez" do
|
||||||
|
error 503 unless Health.instance.healthy?
|
||||||
|
|
||||||
|
return Health.instance.to_json if request.env["HTTP_ACCEPT"] == "application/json"
|
||||||
|
|
||||||
|
Health.instance.to_s
|
||||||
|
end
|
||||||
|
|
||||||
get "/readyz" do
|
get "/readyz" do
|
||||||
error 503 unless Ready.instance.ready?
|
error 503 unless Ready.instance.ready?
|
||||||
|
|
||||||
@ -382,7 +374,7 @@ post "/halt" do
|
|||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
get "/pid" do
|
get "/pid", provides: "json" do
|
||||||
pretty = params.key? :pretty
|
pretty = params.key? :pretty
|
||||||
|
|
||||||
jsonify({ppid: ppid, pid: Process.pid}, pretty:)
|
jsonify({ppid: ppid, pid: Process.pid}, pretty:)
|
||||||
|
@ -15,10 +15,10 @@ type: application
|
|||||||
# This is the chart version. This version number should be incremented each time you make changes
|
# This is the chart version. This version number should be incremented each time you make changes
|
||||||
# to the chart and its templates, including the app version.
|
# to the chart and its templates, including the app version.
|
||||||
# Versions are expected to follow Semantic Versioning (https://semver.org/)
|
# Versions are expected to follow Semantic Versioning (https://semver.org/)
|
||||||
version: 0.1.2
|
version: 0.1.4
|
||||||
|
|
||||||
# This is the version number of the application being deployed. This version number should be
|
# This is the version number of the application being deployed. This version number should be
|
||||||
# incremented each time you make changes to the application. Versions are not expected to
|
# incremented each time you make changes to the application. Versions are not expected to
|
||||||
# follow Semantic Versioning. They should reflect the version the application is using.
|
# follow Semantic Versioning. They should reflect the version the application is using.
|
||||||
# It is recommended to use it with quotes.
|
# It is recommended to use it with quotes.
|
||||||
appVersion: "0.1.2"
|
appVersion: "0.1.4"
|
||||||
|
@ -97,7 +97,7 @@ readinessProbe:
|
|||||||
|
|
||||||
# This section is for setting up autoscaling more information can be found here: https://kubernetes.io/docs/concepts/workloads/autoscaling/
|
# This section is for setting up autoscaling more information can be found here: https://kubernetes.io/docs/concepts/workloads/autoscaling/
|
||||||
autoscaling:
|
autoscaling:
|
||||||
enabled: false
|
enabled: true
|
||||||
minReplicas: 2
|
minReplicas: 2
|
||||||
maxReplicas: 100
|
maxReplicas: 100
|
||||||
targetCPUUtilizationPercentage: 80
|
targetCPUUtilizationPercentage: 80
|
||||||
|
1
config/puma.rb
Normal file
1
config/puma.rb
Normal file
@ -0,0 +1 @@
|
|||||||
|
ENV["PUMA_PID"] = Process.pid.to_s
|
@ -16,7 +16,7 @@ spec:
|
|||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: kubernaut
|
- name: kubernaut
|
||||||
image: git.kill0.net/ryanc/kubernaut:0.1.2
|
image: git.kill0.net/ryanc/kubernaut:0.1.4
|
||||||
imagePullPolicy: Always
|
imagePullPolicy: Always
|
||||||
ports:
|
ports:
|
||||||
- name: sinatra-web
|
- name: sinatra-web
|
||||||
|
Loading…
x
Reference in New Issue
Block a user