MCPcopy
hub / github.com/saltstack/salt / write_systemd_conf

Method write_systemd_conf

tests/support/pkg.py:1611–1647  ·  view source on GitHub ↗
(self, service, binary)

Source from the content-addressed store, hash-verified

1609 atexit.register(plist_file.unlink)
1610
1611 def write_systemd_conf(self, service, binary):
1612 ret = self.proc.run("systemctl", "daemon-reload")
1613 self._check_retcode(ret)
1614 ret = self.proc.run("systemctl", "status", service)
1615 if ret.returncode == 4:
1616 log.warning(
1617 "No systemd unit file was found for service %s. Creating one.", service
1618 )
1619 contents = textwrap.dedent(
1620 """\
1621 [Unit]
1622 Description={service}
1623
1624 [Service]
1625 KillMode=process
1626 Type=notify
1627 NotifyAccess=all
1628 LimitNOFILE=8192
1629 ExecStart={tgt} -c {conf_dir}
1630
1631 [Install]
1632 WantedBy=multi-user.target
1633 """
1634 )
1635 if isinstance(binary, list) and len(binary) == 1:
1636 binary = shutil.which(binary[0]) or binary[0]
1637 elif isinstance(binary, list):
1638 binary = " ".join(binary)
1639 unit_path = pathlib.Path(f"/etc/systemd/system/{service}.service")
1640 contents = contents.format(
1641 service=service, tgt=binary, conf_dir=self.conf_dir
1642 )
1643 log.info("Created '%s'. Contents:\n%s", unit_path, contents)
1644 unit_path.write_text(contents, encoding="utf-8")
1645 ret = self.proc.run("systemctl", "daemon-reload")
1646 atexit.register(unit_path.unlink)
1647 self._check_retcode(ret)
1648
1649 def __enter__(self):
1650 self.update_process_path()

Callers

nothing calls this directly

Calls 5

_check_retcodeMethod · 0.95
warningMethod · 0.80
formatMethod · 0.80
runMethod · 0.45
infoMethod · 0.45

Tested by

no test coverage detected