summaryrefslogtreecommitdiff
path: root/src/modules/services-systemd/main.py
diff options
context:
space:
mode:
authorbill-auger <mr.j.spam.me@gmail.com>2019-03-23 06:40:18 -0400
committerbill-auger <mr.j.spam.me@gmail.com>2019-03-23 06:44:01 -0400
commit89611c7111cdb8b970ac15da089f5ddc64b3b2b1 (patch)
tree6a01272ff02b444f8c9508991f903bc87853da8f /src/modules/services-systemd/main.py
parentf16e94771334e601512dba9fc6969ddfda6e588a (diff)
parent496f9fdaf1f171df777f5628767f7f71bf2e1bea (diff)
merge upstream v3.2.4 with v3.1.9-parabola10
Diffstat (limited to 'src/modules/services-systemd/main.py')
-rw-r--r--src/modules/services-systemd/main.py114
1 files changed, 114 insertions, 0 deletions
diff --git a/src/modules/services-systemd/main.py b/src/modules/services-systemd/main.py
new file mode 100644
index 000000000..7488f0a18
--- /dev/null
+++ b/src/modules/services-systemd/main.py
@@ -0,0 +1,114 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+#
+# === This file is part of Calamares - <https://github.com/calamares> ===
+#
+# Copyright 2014, Philip Müller <philm@manjaro.org>
+# Copyright 2014, Teo Mrnjavac <teo@kde.org>
+# Copyright 2017, Alf Gaida <agaida@siduction.org>
+# Copyright 2018, Adriaan de Groot <groot@kde.org>
+#
+# Calamares is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Calamares is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Calamares. If not, see <http://www.gnu.org/licenses/>.
+
+import libcalamares
+
+
+def systemctl(targets, command, suffix):
+ """
+ For each entry in @p targets, run "systemctl <command> <thing>",
+ where <thing> is the entry's name plus the given @p suffix.
+ (No dot is added between name and suffix; suffix may be empty)
+
+ Returns a failure message, or None if this was successful.
+ Services that are not mandatory have their failures suppressed
+ silently.
+ """
+ for svc in targets:
+ if isinstance(svc, str):
+ name = svc
+ mandatory = False
+ else:
+ name = svc["name"]
+ mandatory = svc.get("mandatory", False)
+
+ ec = libcalamares.utils.target_env_call(
+ ['systemctl', command, "{}{}".format(name, suffix)]
+ )
+
+ if ec != 0:
+ if mandatory:
+ return ("Cannot {} systemd {} {}".format(command, suffix, name),
+ "systemctl {} call in chroot returned error code {}".format(command, ec)
+ )
+ else:
+ libcalamares.utils.warning(
+ "Cannot {} systemd {} {}".format(command, suffix, name)
+ )
+ libcalamares.utils.warning(
+ "systemctl {} call in chroot returned error code {}".format(command, ec)
+ )
+ return None
+
+
+def run():
+ """
+ Setup systemd services
+ """
+ setServices()
+
+ cfg = libcalamares.job.configuration
+ services = cfg['services']
+ targets = cfg['targets']
+ disable = cfg['disable']
+
+ # note that the "systemctl enable" and "systemctl disable" commands used
+ # here will work in a chroot; in fact, they are the only systemctl commands
+ # that support that, see:
+ # http://0pointer.de/blog/projects/changing-roots.html
+
+ r = systemctl(cfg.get("services", []), "enable", ".service")
+ if r is not None:
+ return r
+
+ r = systemctl(cfg.get("targets", []), "enable", ".target")
+ if r is not None:
+ return r
+
+ r = systemctl(cfg.get("disable", []), "disable", ".service")
+ if r is not None:
+ return r
+
+ r = systemctl(cfg.get("disable-targets", []), "disable", ".target")
+ if r is not None:
+ return r
+
+ r = systemctl(cfg.get("mask", []), "mask", "")
+ if r is not None:
+ return r
+
+
+ # This could have just been return r
+ return None
+
+
+def setServices():
+ #init_key = libcalamares.globalstorage.value(GS::INITSYSTEM_KEY)
+ #desktop_key = libcalamares.globalstorage.value(GS::DESKTOP_KEY )
+ init_key = libcalamares.globalstorage.value('default-initsystem') # TODO:
+ desktop_key = libcalamares.globalstorage.value('default-desktop' ) # TODO:
+ config = libcalamares.job.configuration
+ config['services'] = config[init_key + '-services'] + \
+ config[desktop_key + '-services']
+ config['targets' ] = config[init_key + '-targets' ]
+ config['disable' ] = config[init_key + '-disable' ]