Skip to content

Commit

Permalink
Support dynamic-domains
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelWaldvogel committed Feb 10, 2021
1 parent ff3a278 commit dd2f3e0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
22 changes: 12 additions & 10 deletions fs_overlay/etc/services.d/30-dynamic-env/run
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
#!/bin/sh
dir=/var/lib/https-portal/dynamic-env
mkdir -p $dir
env=/var/lib/https-portal/dynamic-env
dom=/var/lib/https-portal/dynamic-domains
mkdir -p $env $dom

# Remember when we started (tiny race condition window)
touch $dir.stamp # Outside of watched dir!
touch $env.stamp # Outside of watched dirs!

# Wait for a modification to an all-uppercase file (ignore temp/swp files)
inotifywait -qm -e close_write,move,delete $dir | while read line
inotifywait -qm -e close_write,move,delete $env $dom | while read line
do
if echo "$line" | grep -q ' [_A-Z]*$'
echo "[dynamic-env] read $line"
if echo "$line" | egrep -q '( [_A-Z]*|\.dom)$'
then
echo "[dynamic-env] All-uppercase file modified in $dir"
echo "[dynamic-env] All-uppercase or .dom file modified"

echo "[dynamic-env] Wait for activity to cease..."
while inotifywait -qq -t 1 -e close_write,move,delete $dir
while inotifywait -qq -t 1 -e close_write,move,delete $env $dom
do
:
done

# Apply new configuration; but only, if anything actually
# changed (top-level "while" loop will continue getting
# potentially old events)
if find $dir -newer $dir.stamp | grep -q .
if find $env $dom -newer $env.stamp | grep -q .
then
# Remember when we started (tiny race condition window)
touch $dir.stamp # Outside of watched dir!
touch $env.stamp # Outside of watched dirs!

echo "[dynamic-env] File changed since last run: Applying new configuration..."
/usr/bin/justc-envdir $dir /bin/reconfig
/usr/bin/justc-envdir $env /bin/reconfig
echo "[dynamic-env] Configuration applied" >&2
else
echo "[dynamic-env] No file changed since last run -- suppressing"
Expand Down
8 changes: 4 additions & 4 deletions fs_overlay/opt/certs_manager/lib/na_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ def self.env_domains
end

def self.auto_discovered_domains
if File.exist? '/var/run/domains'
parse File.read('/var/run/domains')
else
[]
doms = []
Dir['/var/run/domains', "#{NAConfig.portal_base_dir}/dynamic-domains/*.dom"].each do |file|
doms.concat(parse File.read(file))
end
doms
end

def self.debug_mode?
Expand Down

0 comments on commit dd2f3e0

Please sign in to comment.