Compare commits
1 Commits
services-r
...
services-s
| Author | SHA1 | Date | |
|---|---|---|---|
| abf3b69766 |
@@ -1,144 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
#
|
|
||||||
# === This file is part of Calamares - <https://github.com/calamares> ===
|
|
||||||
#
|
|
||||||
# Copyright 2018-2019, Adriaan de Groot <groot@kde.org>
|
|
||||||
# Copyright 2019, Artoo <artoo@artixlinux.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
|
|
||||||
|
|
||||||
from libcalamares.utils import target_env_call, warning
|
|
||||||
from os.path import exists, join
|
|
||||||
|
|
||||||
|
|
||||||
import gettext
|
|
||||||
_ = gettext.translation("calamares-python",
|
|
||||||
localedir=libcalamares.utils.gettext_path(),
|
|
||||||
languages=libcalamares.utils.gettext_languages(),
|
|
||||||
fallback=True).gettext
|
|
||||||
|
|
||||||
|
|
||||||
def pretty_name():
|
|
||||||
return _("Configure Runit services")
|
|
||||||
|
|
||||||
|
|
||||||
class RunitController:
|
|
||||||
"""
|
|
||||||
This is the runit service controller.
|
|
||||||
All of its state comes from global storage and the job
|
|
||||||
configuration at initialization time.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
self.root = libcalamares.globalstorage.value('rootMountPoint')
|
|
||||||
|
|
||||||
# Translate the entries in the config to the actions passed to sv-helper
|
|
||||||
self.services = dict()
|
|
||||||
self.services["enable"] = libcalamares.job.configuration.get('services', [])
|
|
||||||
self.services["disable"] = libcalamares.job.configuration.get('disable', [])
|
|
||||||
|
|
||||||
self.svDir = libcalamares.job.configuration['svDir']
|
|
||||||
self.runsvDir = libcalamares.job.configuration['runsvDir']
|
|
||||||
|
|
||||||
|
|
||||||
def make_failure_description(self, state, name, runlevel):
|
|
||||||
"""
|
|
||||||
Returns a generic "could not <foo>" failure message, specialized
|
|
||||||
for the action @p state and the specific service @p name in @p runlevel.
|
|
||||||
"""
|
|
||||||
if state == "enable":
|
|
||||||
description = _("Cannot enable service {name!s} to run-level {level!s}.")
|
|
||||||
elif state == "disable":
|
|
||||||
description = _("Cannot disable service {name!s} from run-level {level!s}.")
|
|
||||||
else:
|
|
||||||
description = _("Unknown service-action <code>{arg!s}</code> for service {name!s} in run-level {level!s}.")
|
|
||||||
|
|
||||||
return description.format(arg=state, name=name, level=runlevel)
|
|
||||||
|
|
||||||
|
|
||||||
def update(self, state):
|
|
||||||
"""
|
|
||||||
Call sv-helper for each service listed
|
|
||||||
in services for the given @p state.
|
|
||||||
"""
|
|
||||||
|
|
||||||
for svc in self.services.get(state, []):
|
|
||||||
if isinstance(svc, str):
|
|
||||||
name = svc
|
|
||||||
runlevel = "default"
|
|
||||||
mandatory = False
|
|
||||||
else:
|
|
||||||
name = svc["name"]
|
|
||||||
runlevel = svc.get("runlevel", "default")
|
|
||||||
mandatory = svc.get("mandatory", False)
|
|
||||||
|
|
||||||
service_path = self.root + self.svDir + "/" + name
|
|
||||||
runlevel_path = self.root + self.runsvDir + "/" + runlevel
|
|
||||||
src = self.svDir + "/" + name
|
|
||||||
dest = self.runsvDir + "/" + runlevel + "/"
|
|
||||||
|
|
||||||
if state == 'enable':
|
|
||||||
cmd = ["ln", "-sv", src, dest]
|
|
||||||
elif state == 'disable':
|
|
||||||
cmd = ["rm", "-rv", dest]
|
|
||||||
|
|
||||||
if exists(service_path):
|
|
||||||
if exists(runlevel_path):
|
|
||||||
ec = target_env_call(cmd)
|
|
||||||
if ec != 0:
|
|
||||||
warning("Cannot {} service {} to {}".format(state, name, runlevel))
|
|
||||||
warning("{} returned error code {!s}".format(cmd, ec))
|
|
||||||
if mandatory:
|
|
||||||
title = _("Cannot modify service")
|
|
||||||
diagnostic = _("<code>cmd {arg!s}</code> call in chroot returned error code {num!s}.").format(arg=state, num=ec)
|
|
||||||
return (title,
|
|
||||||
self.make_failure_description(state, name, runlevel) + " " + diagnostic
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
warning("Target runlevel {} does not exist for {}.".format(runlevel, name))
|
|
||||||
if mandatory:
|
|
||||||
title = _("Target runlevel does not exist")
|
|
||||||
diagnostic = _("The path for runlevel {level!s} is <code>{path!s}</code>, which does not exist.").format(level=runlevel, path=runlevel_path)
|
|
||||||
|
|
||||||
return (title,
|
|
||||||
self.make_failure_description(state, name, runlevel) + " " + diagnostic
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
warning("Target service {} does not exist in {}.".format(name, self.svDir))
|
|
||||||
if mandatory:
|
|
||||||
title = _("Target service does not exist")
|
|
||||||
diagnostic = _("The path for service {name!s} is <code>{path!s}</code>, which does not exist.").format(name=name, path=service_path)
|
|
||||||
return (title,
|
|
||||||
self.make_failure_description(state, name, runlevel) + " " + diagnostic
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
"""Run the controller
|
|
||||||
"""
|
|
||||||
|
|
||||||
for state in ("enable", "disable"):
|
|
||||||
r = self.update(state)
|
|
||||||
if r is not None:
|
|
||||||
return r
|
|
||||||
|
|
||||||
def run():
|
|
||||||
"""
|
|
||||||
Setup services
|
|
||||||
"""
|
|
||||||
|
|
||||||
return RunitController().run()
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
# runit services module to modify service runlevels via symlinks in the chroot
|
|
||||||
#
|
|
||||||
# Services can be added (to any runlevel, or multiple runlevels) or deleted.
|
|
||||||
# Handle disable with care and only use it if absolutely necessary.
|
|
||||||
#
|
|
||||||
# if a service is listed in the conf but is not present/detected on the target system,
|
|
||||||
# or a runlevel does not exist, it will be ignored and skipped; a warning is logged.
|
|
||||||
#
|
|
||||||
---
|
|
||||||
# svDir: holds the runit service directory location
|
|
||||||
svDir: /etc/runit/sv
|
|
||||||
|
|
||||||
# runsvDir: holds the runlevels directory location
|
|
||||||
runsvDir: /etc/runit/runsvdir
|
|
||||||
|
|
||||||
# services: a list of entries to **enable**
|
|
||||||
# disable: a list of entries to **disable**
|
|
||||||
#
|
|
||||||
# Each entry has three fields:
|
|
||||||
# - name: the service name
|
|
||||||
# - (optional) runlevel: can hold any runlevel present on the target
|
|
||||||
# system; if no runlevel is provided, "default" is assumed.
|
|
||||||
# - (optional) mandatory: if set to true, a failure to modify
|
|
||||||
# the service will result in installation failure, rather than just
|
|
||||||
# a warning. The default is false.
|
|
||||||
#
|
|
||||||
# an entry may also be a single string, which is interpreted
|
|
||||||
# as the name field (runlevel "default" is assumed then, and not-mandatory).
|
|
||||||
#
|
|
||||||
# # Example services and disable settings:
|
|
||||||
# # - add foo1 to default, but it must succeed
|
|
||||||
# # - add foo2 to nonetwork
|
|
||||||
# # - remove foo3 from default
|
|
||||||
# # - remove foo4 from default
|
|
||||||
# services:
|
|
||||||
# - name: foo1
|
|
||||||
# mandatory: true
|
|
||||||
# - name: foo2
|
|
||||||
# runlevel: nonetwork
|
|
||||||
# disable:
|
|
||||||
# - name: foo3
|
|
||||||
# - foo4
|
|
||||||
services: []
|
|
||||||
disable: []
|
|
||||||
101
src/modules/services-s6/main.py
Normal file
101
src/modules/services-s6/main.py
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# === This file is part of Calamares - <https://github.com/calamares> ===
|
||||||
|
#
|
||||||
|
# Copyright 2018-2019, Adriaan de Groot <groot@kde.org>
|
||||||
|
# Copyright 2019, Artoo <artoo@artixlinux.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
|
||||||
|
|
||||||
|
from libcalamares.utils import target_env_call, warning
|
||||||
|
from os.path import exists, join
|
||||||
|
|
||||||
|
|
||||||
|
import gettext
|
||||||
|
_ = gettext.translation("calamares-python",
|
||||||
|
localedir=libcalamares.utils.gettext_path(),
|
||||||
|
languages=libcalamares.utils.gettext_languages(),
|
||||||
|
fallback=True).gettext
|
||||||
|
|
||||||
|
|
||||||
|
def pretty_name():
|
||||||
|
return _("Configure s6 services")
|
||||||
|
|
||||||
|
|
||||||
|
class S6Controller:
|
||||||
|
"""
|
||||||
|
This is the s6 service controller.
|
||||||
|
All of its state comes from global storage and the job
|
||||||
|
configuration at initialization time.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.root = libcalamares.globalstorage.value('rootMountPoint')
|
||||||
|
|
||||||
|
self.svDir = libcalamares.job.configuration['svDir']
|
||||||
|
self.dbDir = libcalamares.job.configuration['dbDir']
|
||||||
|
self.defaultBundle = libcalamares.job.configuration['defaultBundle']
|
||||||
|
|
||||||
|
self.services = dict()
|
||||||
|
self.services["add"] = libcalamares.job.configuration.get('services', [])
|
||||||
|
self.services["delete"] = libcalamares.job.configuration.get('disable', [])
|
||||||
|
|
||||||
|
|
||||||
|
def makeBundle(self):
|
||||||
|
"""
|
||||||
|
Call s6-rc-bundle with each service listed
|
||||||
|
in services as arg.
|
||||||
|
"""
|
||||||
|
|
||||||
|
deleteBundles = self.services.get("delete", [])
|
||||||
|
|
||||||
|
if deleteBundles:
|
||||||
|
ec = target_env_call(["s6-rc-bundle", "-c", self.dbDir, "delete", *deleteBundles])
|
||||||
|
if ec != 0:
|
||||||
|
warning("Cannot delete {}".format(*deleteBundles))
|
||||||
|
warning("s6-rc-bundle returned error code {!s}".format(ec))
|
||||||
|
|
||||||
|
for svc in self.services.get('add', []):
|
||||||
|
ec = target_env_call(["s6-rc-db", "-c", self.dbDir, "type", svc])
|
||||||
|
if ec != 0:
|
||||||
|
warning("Service {} does not exist.".format(svc))
|
||||||
|
warning("s6-rc-db returned error code {!s}".format(ec))
|
||||||
|
else:
|
||||||
|
ec = target_env_call(["s6-service", "add", self.defaultBundle, svc])
|
||||||
|
if ec != 0:
|
||||||
|
warning("Cannot add service {} to {} bundle".format(svc, self.defaultBundle))
|
||||||
|
warning("s6-service returned error code {!s}".format(ec))
|
||||||
|
|
||||||
|
ec = target_env_call(["s6-db-reload", "-r"])
|
||||||
|
if ec != 0:
|
||||||
|
warning("Cannot reload service db.")
|
||||||
|
warning("s6-db-reload returned error code {!s}".format(ec))
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
"""Run the controller
|
||||||
|
"""
|
||||||
|
|
||||||
|
r = self.makeBundle()
|
||||||
|
if r is not None:
|
||||||
|
return r
|
||||||
|
|
||||||
|
def run():
|
||||||
|
"""
|
||||||
|
Setup services
|
||||||
|
"""
|
||||||
|
|
||||||
|
return S6Controller().run()
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
type: "job"
|
type: "job"
|
||||||
name: "services-runit"
|
name: "services-s6"
|
||||||
interface: "python"
|
interface: "python"
|
||||||
script: "main.py"
|
script: "main.py"
|
||||||
33
src/modules/services-s6/services-s6.conf
Normal file
33
src/modules/services-s6/services-s6.conf
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
# s6 services module to create a services bundle via s6-rc-bundle in the chroot
|
||||||
|
#
|
||||||
|
# Services can be added to default bundle
|
||||||
|
# Handle disable with care and only use it if absolutely necessary.
|
||||||
|
#
|
||||||
|
# if a service is listed in the conf but is not present/detected on the target system,
|
||||||
|
# it will be ignored and skipped; a warning is logged.
|
||||||
|
#
|
||||||
|
---
|
||||||
|
|
||||||
|
# services path
|
||||||
|
svDir: /etc/s6/sv
|
||||||
|
|
||||||
|
# database path
|
||||||
|
dbDir: /etc/s6/rc/compiled
|
||||||
|
|
||||||
|
# default bundle name
|
||||||
|
defaultBundle: default
|
||||||
|
|
||||||
|
# services: a list of services to **add** to the default bundle
|
||||||
|
# disable: a list of bundles to **delete**
|
||||||
|
#
|
||||||
|
# Each entry:
|
||||||
|
# - the name
|
||||||
|
# # Example services and disable settings:
|
||||||
|
# services:
|
||||||
|
# - foo1
|
||||||
|
# - foo2
|
||||||
|
# disable:
|
||||||
|
# - foo3
|
||||||
|
# - foo4
|
||||||
|
services: []
|
||||||
|
disable: []
|
||||||
Reference in New Issue
Block a user