Kaynağa Gözat

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

pull/3/head
Shane Mc Cormack 6 yıl önce
ebeveyn
işleme
2bffc11ded
1 değiştirilmiş dosya ile 6 ekleme ve 3 silme
  1. 6
    3
      generate.py

+ 6
- 3
generate.py Dosyayı Görüntüle

21
 fetcher = etcdlib.Connection(args.etcd_host, args.etcd_port, args.etcd_prefix)
21
 fetcher = etcdlib.Connection(args.etcd_host, args.etcd_port, args.etcd_prefix)
22
 
22
 
23
 while True:
23
 while True:
24
+  wroteConfig = False;
24
   services = []
25
   services = []
25
   domains = {k: v.split(',') for k, v in fetcher.get_label('com.chameth.vhost').items()}
26
   domains = {k: v.split(',') for k, v in fetcher.get_label('com.chameth.vhost').items()}
26
   protocols = fetcher.get_label('com.chameth.proxy.protocol')
27
   protocols = fetcher.get_label('com.chameth.proxy.protocol')
40
         'default': container in defaults,
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
   print('Done writing config.', flush=True)
50
   print('Done writing config.', flush=True)
48
 
51
 

Loading…
İptal
Kaydet