From 04e42f0442e14531b9e3243985449beca283b861 Mon Sep 17 00:00:00 2001 From: "Isaac I. Y. Saito" Date: Sun, 28 Jun 2020 02:30:19 -0500 Subject: [PATCH] Option to disable service for systemd. --- src/robot_upstart/install_script.py | 1 + src/robot_upstart/providers.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/robot_upstart/install_script.py b/src/robot_upstart/install_script.py index e23d61c..cd8a76a 100644 --- a/src/robot_upstart/install_script.py +++ b/src/robot_upstart/install_script.py @@ -45,6 +45,7 @@ def get_argument_parser(): p.add_argument("pkgpath", type=str, nargs='+', metavar="pkg/path", help="Package and path to install job launch files from. " + DESC_PKGPATH) + p.add_argument("--disable", action='store_true', help="If set, disable by not placing systemd's unit files. Ignored for upstart.") p.add_argument("--job", type=str, help="Specify job name. If unspecified, will be constructed from package name (first " + "element before underscore is taken, e.g. 'myrobot' if the package name is 'myrobot_bringup').") diff --git a/src/robot_upstart/providers.py b/src/robot_upstart/providers.py index 821257d..ed30f96 100644 --- a/src/robot_upstart/providers.py +++ b/src/robot_upstart/providers.py @@ -48,7 +48,7 @@ class Generic(object): providers are implemented, may provide a place to store configuration common to them. """ - def __init__(self, root, job): + def __init__(self, root, job, disable=False): """ Construct a new Provider. :param root: The filesystem location to prefix all file-install @@ -56,9 +56,12 @@ def __init__(self, root, job): :type root: str :param job: The job definition to transform to a set of system files. :type job: :py:class:robot_upstart.Job + :param disable: If True, service will be disabled. + :type disable: bool """ self.root = root self.job = job + self.disable = disable # Recipe structure which is serialized to yaml and passed to the mutate_files script. self.installation_files = {} @@ -177,9 +180,10 @@ def generate_install(self): self.installation_files[os.path.join(self.root, "lib/systemd/system", self.job.name + ".service")] = { "content": self._fill_template("templates/systemd_job.conf.em"), "mode": 0o644} - self.installation_files[os.path.join(self.root, "etc/systemd/system/multi-user.target.wants", - self.job.name + ".service")] = { - "symlink": os.path.join(self.root, "lib/systemd/system/", self.job.name + ".service")} + if self.disable: + self.installation_files[os.path.join(self.root, "etc/systemd/system/multi-user.target.wants", + self.job.name + ".service")] = { + "symlink": os.path.join(self.root, "lib/systemd/system/", self.job.name + ".service")} self.installation_files[os.path.join(self.root, "usr/sbin", self.job.name + "-start")] = { "content": self._fill_template("templates/job-start.em"), "mode": 0o755} self.installation_files[os.path.join(self.root, "usr/sbin", self.job.name + "-stop")] = {