Commit 4ca9d27d authored by Jameson Rollins's avatar Jameson Rollins

guardctrl: allow using guardctrl for units under different name

primarily for test purposes
parent 360066ee
......@@ -10,9 +10,11 @@ from . import util
##################################################
NAME = os.getenv('GUARDNAME', 'guardian')
SYSTEMCTL_CMD = ['systemctl', '--user']
GUARD_TARGET_PATH = os.path.expanduser('~/.config/systemd/user/guardian.target.wants')
UNIT2NODE_RE = re.compile('guardian@(.*).service')
UNIT_FMT = '{}@{{}}.service'.format(NAME)
UNIT2NODE_RE = re.compile(UNIT_FMT.format('(.*)'))
JOURNALCTL_TIME_FMT = '%Y-%m-%d %X'
##################################################
......@@ -23,7 +25,7 @@ class SystemctlError(Exception):
def systemctl_cmd(*args, nodes='*', check=True, **kwargs):
cmd = SYSTEMCTL_CMD + list(args)
if nodes:
cmd += ['guardian@{}.service'.format(node) for node in nodes]
cmd += [UNIT_FMT.format(node) for node in nodes]
logging.debug('cmd: ' + ' '.join(cmd))
try:
proc = subprocess.run(cmd, check=check, **kwargs)
......@@ -288,7 +290,7 @@ def node_logs(nodes=None,
if follow:
cmd += ['--follow']
for node in nodes:
cmd += ['--user-unit=guardian@{}.service'.format(node)]
cmd += ['--user-unit={}'.format(UNIT_FMT.format(node))]
logging.debug('cmd: ' + ' '.join(cmd))
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment