Merge pull request #261 from modoboa/feature/upgrade_mode
Installer upgrade mode.
This commit is contained in:
@@ -6,7 +6,7 @@ import sys
|
||||
from .. import utils
|
||||
|
||||
|
||||
def install(appname, config):
|
||||
def install(appname, config, upgrade):
|
||||
"""Install an application."""
|
||||
if (config.has_option(appname, "enabled") and
|
||||
not config.getboolean(appname, "enabled")):
|
||||
@@ -19,7 +19,7 @@ def install(appname, config):
|
||||
print("Unknown application {}".format(appname))
|
||||
sys.exit(1)
|
||||
try:
|
||||
getattr(script, appname.capitalize())(config).run()
|
||||
getattr(script, appname.capitalize())(config, upgrade).run()
|
||||
except utils.FatalError as inst:
|
||||
utils.printcolor(u"{}".format(inst), utils.RED)
|
||||
sys.exit(1)
|
||||
|
||||
@@ -85,5 +85,5 @@ class Amavis(base.Installer):
|
||||
"""Additional tasks."""
|
||||
with open("/etc/mailname", "w") as fp:
|
||||
fp.write("{}\n".format(self.config.get("general", "hostname")))
|
||||
install("spamassassin", self.config)
|
||||
install("clamav", self.config)
|
||||
install("spamassassin", self.config, self.upgrade)
|
||||
install("clamav", self.config, self.upgrade)
|
||||
|
||||
@@ -24,11 +24,11 @@ class Automx(base.Installer):
|
||||
}
|
||||
with_user = True
|
||||
|
||||
def __init__(self, config):
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""Get configuration."""
|
||||
super(Automx, self).__init__(config)
|
||||
self.venv_path = config.get("automx", "venv_path")
|
||||
self.instance_path = config.get("automx", "instance_path")
|
||||
super(Automx, self).__init__(*args, **kwargs)
|
||||
self.venv_path = self.config.get("automx", "venv_path")
|
||||
self.instance_path = self.config.get("automx", "instance_path")
|
||||
|
||||
def get_template_context(self):
|
||||
"""Additional variables."""
|
||||
|
||||
@@ -19,9 +19,10 @@ class Installer(object):
|
||||
with_db = False
|
||||
config_files = []
|
||||
|
||||
def __init__(self, config):
|
||||
def __init__(self, config, upgrade):
|
||||
"""Get configuration."""
|
||||
self.config = config
|
||||
self.upgrade = upgrade
|
||||
if self.config.has_section(self.appname):
|
||||
self.app_config = dict(self.config.items(self.appname))
|
||||
self.dbengine = self.config.get("database", "engine")
|
||||
@@ -67,8 +68,8 @@ class Installer(object):
|
||||
self.backend.load_sql_file(
|
||||
self.dbname, self.dbuser, self.dbpasswd, schema)
|
||||
|
||||
def create_user(self):
|
||||
"""Create a system user."""
|
||||
def setup_user(self):
|
||||
"""Setup a system user."""
|
||||
if not self.with_user:
|
||||
return
|
||||
self.user = self.config.get(self.appname, "user")
|
||||
@@ -143,8 +144,9 @@ class Installer(object):
|
||||
def run(self):
|
||||
"""Run the installer."""
|
||||
self.install_packages()
|
||||
self.create_user()
|
||||
self.setup_database()
|
||||
self.setup_user()
|
||||
if not self.upgrade:
|
||||
self.setup_database()
|
||||
self.install_config_files()
|
||||
self.post_run()
|
||||
self.restart_daemon()
|
||||
|
||||
@@ -36,13 +36,13 @@ class Modoboa(base.Installer):
|
||||
with_db = True
|
||||
with_user = True
|
||||
|
||||
def __init__(self, config):
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""Get configuration."""
|
||||
super(Modoboa, self).__init__(config)
|
||||
self.venv_path = config.get("modoboa", "venv_path")
|
||||
self.instance_path = config.get("modoboa", "instance_path")
|
||||
self.extensions = config.get("modoboa", "extensions").split()
|
||||
self.devmode = config.getboolean("modoboa", "devmode")
|
||||
super(Modoboa, self).__init__(*args, **kwargs)
|
||||
self.venv_path = self.config.get("modoboa", "venv_path")
|
||||
self.instance_path = self.config.get("modoboa", "instance_path")
|
||||
self.extensions = self.config.get("modoboa", "extensions").split()
|
||||
self.devmode = self.config.getboolean("modoboa", "devmode")
|
||||
# Sanity check for amavis
|
||||
self.amavis_enabled = False
|
||||
if "modoboa-amavis" in self.extensions:
|
||||
@@ -87,7 +87,8 @@ class Modoboa(base.Installer):
|
||||
packages.append(extension)
|
||||
# Temp fix for https://github.com/modoboa/modoboa-installer/issues/197
|
||||
python.install_package(
|
||||
modoboa_package, self.venv_path, binary=False, sudo_user=self.user)
|
||||
modoboa_package, self.venv_path,
|
||||
upgrade=self.upgrade, binary=False, sudo_user=self.user)
|
||||
if self.dbengine == "postgres":
|
||||
packages.append("psycopg2-binary")
|
||||
else:
|
||||
@@ -99,18 +100,23 @@ class Modoboa(base.Installer):
|
||||
# Temp. fix
|
||||
packages += [
|
||||
"https://github.com/modoboa/caldav/tarball/master#egg=caldav"]
|
||||
python.install_packages(packages, self.venv_path, sudo_user=self.user)
|
||||
python.install_packages(
|
||||
packages, self.venv_path, upgrade=self.upgrade, sudo_user=self.user)
|
||||
if self.devmode:
|
||||
# FIXME: use dev-requirements instead
|
||||
python.install_packages(
|
||||
["django-bower", "django-debug-toolbar"], self.venv_path,
|
||||
sudo_user=self.user)
|
||||
upgrade=self.upgrade, sudo_user=self.user)
|
||||
|
||||
def _deploy_instance(self):
|
||||
"""Deploy Modoboa."""
|
||||
target = os.path.join(self.home_dir, "instance")
|
||||
if os.path.exists(target):
|
||||
if not self.config.getboolean("general", "force"):
|
||||
condition = (
|
||||
not self.upgrade and
|
||||
not self.config.getboolean("general", "force")
|
||||
)
|
||||
if condition:
|
||||
utils.printcolor(
|
||||
"Target directory for Modoboa deployment ({}) already "
|
||||
"exists. If you choose to continue, it will be removed."
|
||||
@@ -239,4 +245,5 @@ class Modoboa(base.Installer):
|
||||
"""Additional tasks."""
|
||||
self._setup_venv()
|
||||
self._deploy_instance()
|
||||
self.apply_settings()
|
||||
if not self.upgrade:
|
||||
self.apply_settings()
|
||||
|
||||
@@ -25,7 +25,8 @@ class Nginx(base.Installer):
|
||||
context.update({
|
||||
"app_instance_path": (
|
||||
self.config.get(app, "instance_path")),
|
||||
"uwsgi_socket_path": Uwsgi(self.config).get_socket_path(app)
|
||||
"uwsgi_socket_path": (
|
||||
Uwsgi(self.config, self.upgrade).get_socket_path(app))
|
||||
})
|
||||
return context
|
||||
|
||||
|
||||
@@ -97,4 +97,4 @@ class Postfix(base.Installer):
|
||||
utils.exec_cmd("postalias {}".format(aliases_file))
|
||||
|
||||
# Postwhite
|
||||
install("postwhite", self.config)
|
||||
install("postwhite", self.config, self.upgrade)
|
||||
|
||||
@@ -22,10 +22,10 @@ class Radicale(base.Installer):
|
||||
}
|
||||
with_user = True
|
||||
|
||||
def __init__(self, config):
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""Get configuration."""
|
||||
super(Radicale, self).__init__(config)
|
||||
self.venv_path = config.get("radicale", "venv_path")
|
||||
super(Radicale, self).__init__(*args, **kwargs)
|
||||
self.venv_path = self.config.get("radicale", "venv_path")
|
||||
|
||||
def _setup_venv(self):
|
||||
"""Prepare a dedicated virtualenv."""
|
||||
|
||||
@@ -61,7 +61,7 @@ class Spamassassin(base.Installer):
|
||||
"pyzor --homedir {} discover".format(pw[5]),
|
||||
sudo_user=amavis_user, login=False
|
||||
)
|
||||
install("razor", self.config)
|
||||
install("razor", self.config, self.upgrade)
|
||||
if utils.dist_name() in ["debian", "ubuntu"]:
|
||||
utils.exec_cmd(
|
||||
"perl -pi -e 's/^CRON=0/CRON=1/' /etc/cron.daily/spamassassin")
|
||||
|
||||
Reference in New Issue
Block a user