瀏覽代碼

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

pull/3/head
Shane Mc Cormack 6 年之前
父節點
當前提交
2bffc11ded
共有 1 個檔案被更改,包括 6 行新增3 行删除
  1. 6
    3
      generate.py

+ 6
- 3
generate.py 查看文件

@@ -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…
取消
儲存