source: calamares/trunk/fuentes/src/modules/services/main.py @ 7538

Last change on this file since 7538 was 7538, checked in by kbut, 13 months ago

sync with github

File size: 3.7 KB
Line 
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3#
4# === This file is part of Calamares - <https://github.com/calamares> ===
5#
6#   Copyright 2014, Philip Müller <philm@manjaro.org>
7#   Copyright 2014, Teo Mrnjavac <teo@kde.org>
8#   Copyright 2017, Alf Gaida <agaida@siduction.org>
9#
10#   Calamares is free software: you can redistribute it and/or modify
11#   it under the terms of the GNU General Public License as published by
12#   the Free Software Foundation, either version 3 of the License, or
13#   (at your option) any later version.
14#
15#   Calamares is distributed in the hope that it will be useful,
16#   but WITHOUT ANY WARRANTY; without even the implied warranty of
17#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18#   GNU General Public License for more details.
19#
20#   You should have received a copy of the GNU General Public License
21#   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
22
23import libcalamares
24
25
26def run():
27    """
28    Setup systemd services
29    """
30    services = libcalamares.job.configuration['services']
31    targets = libcalamares.job.configuration['targets']
32    disable = libcalamares.job.configuration['disable']
33
34    # note that the "systemctl enable" and "systemctl disable" commands used
35    # here will work in a chroot; in fact, they are the only systemctl commands
36    # that support that, see:
37    # http://0pointer.de/blog/projects/changing-roots.html
38
39    # enable services
40    for svc in services:
41        ec = libcalamares.utils.target_env_call(
42            ['systemctl', 'enable', '{}.service'.format(svc['name'])]
43            )
44
45        if ec != 0:
46            if svc['mandatory']:
47                return ("Cannot enable systemd service {}".format(svc['name']),
48                        "systemctl enable call in chroot returned error code "
49                        "{}".format(ec)
50                        )
51            else:
52                libcalamares.utils.debug(
53                    "Cannot enable systemd service {}".format(svc['name'])
54                    )
55                libcalamares.utils.debug(
56                    "systemctl enable call in chroot returned error code "
57                    "{}".format(ec)
58                    )
59
60    # enable targets
61    for tgt in targets:
62        ec = libcalamares.utils.target_env_call(
63            ['systemctl', 'enable', '{}.target'.format(tgt['name'])]
64            )
65
66        if ec != 0:
67            if tgt['mandatory']:
68                return ("Cannot enable systemd target {}".format(tgt['name']),
69                        "systemctl enable call in chroot returned error code"
70                        "{}".format(ec)
71                        )
72            else:
73                libcalamares.utils.debug(
74                    "Cannot enable systemd target {}".format(tgt['name'])
75                    )
76                libcalamares.utils.debug(
77                    "systemctl enable call in chroot returned error code "
78                    "{}".format(ec)
79                    )
80
81    for dbl in disable:
82        ec = libcalamares.utils.target_env_call(
83            ['systemctl', 'disable', '{}.service'.format(dbl['name'])]
84            )
85
86        if ec != 0:
87            if dbl['mandatory']:
88                return ("Cannot disable systemd service"
89                        "{}".format(dbl['name']),
90                        "systemctl disable call in chroot returned error code"
91                        "{}".format(ec))
92            else:
93                libcalamares.utils.debug(
94                    "Cannot disable systemd service {}".format(dbl['name'])
95                    )
96                libcalamares.utils.debug(
97                    "systemctl disable call in chroot returned error code "
98                    "{}".format(ec)
99                    )
100
101    return None
Note: See TracBrowser for help on using the repository browser.