Browse Source

Refuse to overwrite an existing config with a blank one unless we wrote it.

pull/3/head
Shane Mc Cormack 6 years ago
parent
commit
2bffc11ded
1 changed files with 6 additions and 3 deletions
  1. 6
    3
      generate.py

+ 6
- 3
generate.py View File

@@ -21,6 +21,7 @@ template = jinja_env.get_template('nginx.tpl')
21 21
 fetcher = etcdlib.Connection(args.etcd_host, args.etcd_port, args.etcd_prefix)
22 22
 
23 23
 while True:
24
+  wroteConfig = False;
24 25
   services = []
25 26
   domains = {k: v.split(',') for k, v in fetcher.get_label('com.chameth.vhost').items()}
26 27
   protocols = fetcher.get_label('com.chameth.proxy.protocol')
@@ -40,9 +41,11 @@ while True:
40 41
         'default': container in defaults,
41 42
       })
42 43
 
43
-  with open('/nginx-config/vhosts.conf', 'w') as f:
44
-    print('Writing vhosts.conf...', flush=True)
45
-    f.write(template.render(services=services))
44
+  if wroteConfig or len(services) > 0 or not os.path.isfile('/nginx-config/vhosts.conf'):
45
+    with open('/nginx-config/vhosts.conf', 'w') as f:
46
+      print('Writing vhosts.conf...', flush=True)
47
+      f.write(template.render(services=services))
48
+      wroteConfig = True;
46 49
 
47 50
   print('Done writing config.', flush=True)
48 51
 

Loading…
Cancel
Save