Make caddy reload reactive on modified file
This commit is contained in:
parent
46ff8fc584
commit
de46e9864b
@ -15,4 +15,12 @@ http://*:8888 {
|
||||
handle_path /admin/* {
|
||||
reverse_proxy /* http://127.0.0.1:3000
|
||||
}
|
||||
|
||||
handle_path /faaso/exp/* {
|
||||
reverse_proxy /* http://faaso-exp-6ne49v:3000 {
|
||||
health_uri /ping
|
||||
fail_duration 30s
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,6 +36,10 @@ shards:
|
||||
git: https://github.com/mamantoha/http_proxy.git
|
||||
version: 0.10.3
|
||||
|
||||
inotify:
|
||||
git: https://github.com/petoem/inotify.cr.git
|
||||
version: 1.0.3
|
||||
|
||||
kemal:
|
||||
git: https://github.com/kemalcr/kemal.git
|
||||
version: 1.5.0
|
||||
|
@ -30,6 +30,8 @@ dependencies:
|
||||
github: kemalcr/kemal
|
||||
rucksack:
|
||||
github: busyloop/rucksack
|
||||
inotify:
|
||||
github: petoem/inotify.cr
|
||||
|
||||
scripts:
|
||||
postinstall: cat .rucksack >> bin/faaso
|
@ -1,11 +1,17 @@
|
||||
require "docr"
|
||||
require "./funko.cr"
|
||||
require "docr"
|
||||
require "inotify"
|
||||
require "kemal"
|
||||
|
||||
module Proxy
|
||||
CADDY_CONFIG_PATH = "config/Caddyfile"
|
||||
@@current_config = File.read(CADDY_CONFIG_PATH)
|
||||
|
||||
@@watcher = Inotify.watch(CADDY_CONFIG_PATH) do |_|
|
||||
Log.info { "Reloading caddy config" }
|
||||
Process.run(command: "caddy", args: ["reload", "--config", CADDY_CONFIG_PATH])
|
||||
end
|
||||
|
||||
# Get current proxy config
|
||||
get "/proxy/" do
|
||||
@@current_config
|
||||
@ -69,14 +75,13 @@ CONFIG
|
||||
file << config
|
||||
end
|
||||
# Reload config
|
||||
Process.run(command: "caddy", args: ["reload", "--config", "Caddyfile"])
|
||||
@@current_config = config
|
||||
end
|
||||
config
|
||||
end
|
||||
end
|
||||
|
||||
# Update proxy config once a second
|
||||
# Update proxy config every 1 second (if changed)
|
||||
spawn do
|
||||
loop do
|
||||
Proxy.update_proxy_config
|
||||
|
Loading…
Reference in New Issue
Block a user