diff --git a/basic/usr/local/bin/spotter-appmgr b/basic/usr/local/bin/spotter-appmgr index 447a522..bdd14be 100755 --- a/basic/usr/local/bin/spotter-appmgr +++ b/basic/usr/local/bin/spotter-appmgr @@ -7,7 +7,6 @@ import os import subprocess CONF_FILE = '/etc/spotter/apps.json' -HOSTS_FILE = '/etc/hosts' ISSUE_FILE = '/etc/issue' NGINX_DIR = '/etc/nginx/conf.d' @@ -19,7 +18,7 @@ NGINX_TEMPLATE = '''server {{ error_log /var/log/nginx/{app}.error.log; location / {{ - proxy_pass http://{app}:8080; + proxy_pass http://{ip}:8080; }} }} ''' @@ -103,8 +102,6 @@ class SpotterManager: self.add_app_to_conf(app, args) if args.url: self.update_app_conf(app) - self.add_app_to_nginx(app) - self.reload_nginx() def add_app_to_conf(self, app, args): self.conf[app] = {} @@ -123,22 +120,18 @@ class SpotterManager: host = '{}.{}'.format(app, self.domain) subprocess.call([script_path, host, self.port]) + def update_proxy(self, app): + self.add_app_to_nginx(app) + self.reload_nginx() + def add_app_to_nginx(self, app): + ip = get_container_ip(app) with open(os.path.join(NGINX_DIR, '{}.conf'.format(app)), 'w') as f: - f.write(NGINX_TEMPLATE.format(app=app, domain=self.domain, port=self.port)) + f.write(NGINX_TEMPLATE.format(app=app, ip=ip, domain=self.domain, port=self.port)) def reload_nginx(self): subprocess.call(['service', 'nginx', 'reload']) - def update_hosts(self, app): - with open(HOSTS_FILE, 'r') as f: - lines = f.readlines() - with open(HOSTS_FILE, 'w') as f: - for line in lines: - if not line.strip().endswith(' {}'.format(app)): - f.write(line) - f.write('{} {}\n'.format(get_container_ip(app), app)) - def update_domain(self, domain, port): self.domain = self.conf["_"]["domain"] = domain self.port = self.conf["_"]["port"] = port @@ -179,7 +172,7 @@ if __name__ == '__main__': parser = argparse.ArgumentParser(description='Spotter VM application manager') subparsers = parser.add_subparsers() - parser_add_app = subparsers.add_parser('add-app', help='Registers a new application and creates hosts and nginx definition for it') + parser_add_app = subparsers.add_parser('add-app', help='Registers a new application') parser_add_app.set_defaults(action='add-app') parser_add_app.add_argument('app', help='Application name') parser_add_app.add_argument('url', nargs='?', help='URL to the application. Use "{host}" as a host placeholder') @@ -187,9 +180,9 @@ if __name__ == '__main__': parser_add_app.add_argument('password', nargs='?', help='Administrative password') parser_add_app.add_argument('-p', '--property', nargs=2, action='append', help='Add arbitrary key-value to the application properties') - parser_update_app = subparsers.add_parser('update-hosts', help='Updates hosts definition for application container') - parser_update_app.set_defaults(action='update-hosts') - parser_update_app.add_argument('app', help='Application name') + parser_update_proxy = subparsers.add_parser('update-proxy', help='Updates nginx proxy target for an application container') + parser_update_proxy.set_defaults(action='update-proxy') + parser_update_proxy.add_argument('app', help='Application name') parser_update_domain = subparsers.add_parser('update-domain', help='Rebuilds domain structure of VM with new domain name and new HTTPS port') parser_update_domain.set_defaults(action='update-domain') @@ -200,7 +193,7 @@ if __name__ == '__main__': sm = SpotterManager() if args.action == 'add-app': sm.add_app(args.app, args) - elif args.action == 'update-hosts': - sm.update_hosts(args.app) + elif args.action == 'update-proxy': + sm.update_proxy(args.app) elif args.action == 'update-domain': sm.update_domain(args.domain, args.port) diff --git a/ccleanup/etc/init.d/ccleanup b/ccleanup/etc/init.d/ccleanup index 828ff96..19f733d 100755 --- a/ccleanup/etc/init.d/ccleanup +++ b/ccleanup/etc/init.d/ccleanup @@ -18,7 +18,7 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-hosts ccleanup + /usr/local/bin/spotter-appmgr update-proxy ccleanup } stop() { diff --git a/ckan/etc/init.d/ckan b/ckan/etc/init.d/ckan index 0eea32a..c1a88d6 100755 --- a/ckan/etc/init.d/ckan +++ b/ckan/etc/init.d/ckan @@ -23,7 +23,7 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-hosts ckan + /usr/local/bin/spotter-appmgr update-proxy ckan } stop() { diff --git a/cts/etc/init.d/cts b/cts/etc/init.d/cts index e1d93a2..c87bb4d 100755 --- a/cts/etc/init.d/cts +++ b/cts/etc/init.d/cts @@ -17,7 +17,7 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-hosts cts + /usr/local/bin/spotter-appmgr update-proxy cts } stop() { diff --git a/gnuhealth/etc/init.d/gnuhealth b/gnuhealth/etc/init.d/gnuhealth index f86c576..5c1f59c 100755 --- a/gnuhealth/etc/init.d/gnuhealth +++ b/gnuhealth/etc/init.d/gnuhealth @@ -18,7 +18,7 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-hosts gnuhealth + /usr/local/bin/spotter-appmgr update-proxy gnuhealth } stop() { diff --git a/kanboard/etc/init.d/kanboard b/kanboard/etc/init.d/kanboard index b17d5a6..d959c4f 100755 --- a/kanboard/etc/init.d/kanboard +++ b/kanboard/etc/init.d/kanboard @@ -19,7 +19,7 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-hosts kanboard + /usr/local/bin/spotter-appmgr update-proxy kanboard } stop() { diff --git a/mifosx/etc/init.d/mifosx b/mifosx/etc/init.d/mifosx index 6005bfd..58da091 100755 --- a/mifosx/etc/init.d/mifosx +++ b/mifosx/etc/init.d/mifosx @@ -19,7 +19,7 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-hosts mifosx + /usr/local/bin/spotter-appmgr update-proxy mifosx } stop() { diff --git a/motech/etc/init.d/motech b/motech/etc/init.d/motech index 5098f07..aa9621e 100755 --- a/motech/etc/init.d/motech +++ b/motech/etc/init.d/motech @@ -19,7 +19,7 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-hosts motech + /usr/local/bin/spotter-appmgr update-proxy motech } stop() { diff --git a/odk/etc/init.d/odk b/odk/etc/init.d/odk index 2ec2925..91cdb3c 100755 --- a/odk/etc/init.d/odk +++ b/odk/etc/init.d/odk @@ -20,7 +20,7 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-hosts odk + /usr/local/bin/spotter-appmgr update-proxy odk } stop() { diff --git a/odkbuild/etc/init.d/odkbuild b/odkbuild/etc/init.d/odkbuild index 067d5bf..cd62c5b 100755 --- a/odkbuild/etc/init.d/odkbuild +++ b/odkbuild/etc/init.d/odkbuild @@ -17,7 +17,7 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-hosts odkbuild + /usr/local/bin/spotter-appmgr update-proxy odkbuild } stop() { diff --git a/omk/etc/init.d/omk b/omk/etc/init.d/omk index 812aa5f..b1e2b89 100755 --- a/omk/etc/init.d/omk +++ b/omk/etc/init.d/omk @@ -17,7 +17,7 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-hosts omk + /usr/local/bin/spotter-appmgr update-proxy omk } stop() { diff --git a/pandora/etc/init.d/pandora b/pandora/etc/init.d/pandora index d49ddd7..63b5e40 100755 --- a/pandora/etc/init.d/pandora +++ b/pandora/etc/init.d/pandora @@ -20,7 +20,7 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-hosts pandora + /usr/local/bin/spotter-appmgr update-proxy pandora } stop() { diff --git a/sahana-demo/etc/init.d/sahana-demo b/sahana-demo/etc/init.d/sahana-demo index 1f400a2..db3ed0e 100755 --- a/sahana-demo/etc/init.d/sahana-demo +++ b/sahana-demo/etc/init.d/sahana-demo @@ -21,7 +21,7 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-hosts sahana-demo + /usr/local/bin/spotter-appmgr update-proxy sahana-demo } stop() { diff --git a/sahana/etc/init.d/sahana b/sahana/etc/init.d/sahana index d28e990..91084d7 100755 --- a/sahana/etc/init.d/sahana +++ b/sahana/etc/init.d/sahana @@ -21,7 +21,7 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-hosts sahana + /usr/local/bin/spotter-appmgr update-proxy sahana } stop() { diff --git a/sambro/etc/init.d/sambro b/sambro/etc/init.d/sambro index 4374932..a69b895 100755 --- a/sambro/etc/init.d/sambro +++ b/sambro/etc/init.d/sambro @@ -21,7 +21,7 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-hosts sambro + /usr/local/bin/spotter-appmgr update-proxy sambro } stop() { diff --git a/seeddms/etc/init.d/seeddms b/seeddms/etc/init.d/seeddms index fe03e72..b4aca02 100755 --- a/seeddms/etc/init.d/seeddms +++ b/seeddms/etc/init.d/seeddms @@ -19,7 +19,7 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-hosts seeddms + /usr/local/bin/spotter-appmgr update-proxy seeddms } stop() { diff --git a/sigmah/etc/init.d/sigmah b/sigmah/etc/init.d/sigmah index 25fb01e..ec35d22 100755 --- a/sigmah/etc/init.d/sigmah +++ b/sigmah/etc/init.d/sigmah @@ -20,7 +20,7 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-hosts sigmah + /usr/local/bin/spotter-appmgr update-proxy sigmah } stop() { diff --git a/ushahidi/etc/init.d/ushahidi b/ushahidi/etc/init.d/ushahidi index 3a3ec1c..1012ed3 100755 --- a/ushahidi/etc/init.d/ushahidi +++ b/ushahidi/etc/init.d/ushahidi @@ -20,7 +20,7 @@ start() { } start_post() { - /usr/local/bin/spotter-appmgr update-hosts ushahidi + /usr/local/bin/spotter-appmgr update-proxy ushahidi } stop() {