diff --git a/usr/bin/vmmgr b/usr/bin/vmmgr index 4118c8f..b1aa53e 100755 --- a/usr/bin/vmmgr +++ b/usr/bin/vmmgr @@ -15,6 +15,10 @@ parser_register_app.add_argument('app', help='Application name') parser_register_app.add_argument('login', nargs='?', help='Admin login') parser_register_app.add_argument('password', nargs='?', help='Admin password') +parser_unregister_app = subparsers.add_parser('unregister-app') +parser_unregister_app.set_defaults(action='unregister-app') +parser_unregister_app.add_argument('app', help='Application name') + parser_rebuild_issue = subparsers.add_parser('rebuild-issue') parser_rebuild_issue.set_defaults(action='rebuild-issue') @@ -42,23 +46,26 @@ parser_unregister_proxy.add_argument('app', help='Application name') args = parser.parse_args() vmmgr = VMMgr(Config()) if args.action == 'register-app': - # Used by app install scripts + # Used by package install.sh script vmmgr.register_app(args.app, args.login, args.password) +elif args.action == 'unregister-app': + # Used by package uninstall.sh script + vmmgr.unregister_app(args.app) elif args.action == 'rebuild-issue': - # Used on VM startup + # Used by inittab on VM startup vmmgr.rebuild_issue() elif args.action == 'prepare-container': - # Used with LXC hooks + # Used with LXC hooks on container startup lxcmgr.prepare_container() elif args.action == 'register-container': - # Used with LXC hooks + # Used with LXC hooks on container startup lxcmgr.register_container() elif args.action == 'unregister-container': - # Used with LXC hooks + # Used with LXC hooks on container stop lxcmgr.unregister_container() elif args.action == 'register-proxy': - # Used in init scripts + # Used in init scripts on application startup vmmgr.register_proxy(args.app, args.host) elif args.action == 'unregister-proxy': - # Used in init scripts + # Used in init scripts on application stop vmmgr.unregister_proxy(args.app) diff --git a/usr/lib/python3.6/vmmgr/appmgr.py b/usr/lib/python3.6/vmmgr/appmgr.py index d44a738..2c9197b 100644 --- a/usr/lib/python3.6/vmmgr/appmgr.py +++ b/usr/lib/python3.6/vmmgr/appmgr.py @@ -79,9 +79,7 @@ class AppMgr: self.stop_app(item) if self.is_service_autostarted(app): self.update_app_autostart(app, False) - if name in self.conf['apps']: - del self.conf['apps'][name] - subprocess.run(['apk', '--no-cache', 'del', 'vm-{}@vm'.format(app)], check=True) + subprocess.run(['apk', '--no-cache', 'del', 'vm-{}'.format(app)], check=True) def fetch_online_packages(self, repo_conf): # Fetches list of online packages diff --git a/usr/lib/python3.6/vmmgr/vmmgr.py b/usr/lib/python3.6/vmmgr/vmmgr.py index e414d11..b63202f 100644 --- a/usr/lib/python3.6/vmmgr/vmmgr.py +++ b/usr/lib/python3.6/vmmgr/vmmgr.py @@ -20,15 +20,25 @@ class VMMgr: self.port = conf['host']['port'] def register_app(self, app, login, password): - # Register newly installed application, its metadata and credentials + # Register newly installed application, its metadata and credentials (called at the end of package install.sh) with open('/var/lib/lxcpkgs/{}/meta'.format(app)) as f: meta = json.load(f) self.conf['apps'][app] = {**meta, 'login': login if login else 'N/A', 'password': password if password else 'N/A', 'visible': False} - self.conf.save() + self.save_and_reload_config() + + def unregister_app(self, app): + # Unregister application during uninstallation (called at the end of package uninstall.sh) + if app not in self.conf['apps']: + return + del self.conf['apps'][app] + self.save_and_reload_config() + + def reload_config(self): # Attempt to contact running vmmgr WSGI application to reload config + self.conf.save() try: requests.get('http://127.0.0.1:8080/reload-config', timeout=3) except: