2022-12-23 11:26:50 -05:00
|
|
|
#! /usr/bin/env python3
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from string import Template
|
|
|
|
from subprocess import check_call
|
2022-12-23 12:37:27 -05:00
|
|
|
from subprocess import check_output
|
2022-12-23 11:26:50 -05:00
|
|
|
|
|
|
|
EXEC = 'chutney.py'
|
|
|
|
SERVICE = 'chutney.service'
|
|
|
|
SYSTEM_DIR = '/etc/systemd/system'
|
|
|
|
|
|
|
|
CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
SERVICE_TEMPLATE = os.path.join(CURRENT_DIR, SERVICE)
|
|
|
|
SERVICE_FILE = os.path.join(SYSTEM_DIR, SERVICE)
|
|
|
|
PYTHON = sys.executable
|
|
|
|
EXEC_START = f'{PYTHON} {EXEC}'
|
2022-12-23 12:37:27 -05:00
|
|
|
USER = check_output(['logname']).decode('utf-8').strip()
|
2022-12-23 11:26:50 -05:00
|
|
|
|
|
|
|
with open(SERVICE_TEMPLATE) as f:
|
|
|
|
serviceTemplate = Template(f.read())
|
|
|
|
|
|
|
|
serviceFile = serviceTemplate.substitute(
|
|
|
|
workingDirectory=CURRENT_DIR,
|
2022-12-23 12:37:27 -05:00
|
|
|
execStart=EXEC_START,
|
|
|
|
user=USER
|
2022-12-23 11:26:50 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
with open(SERVICE_FILE, 'w') as f:
|
|
|
|
f.write(serviceFile)
|
|
|
|
|
|
|
|
check_call(['systemctl', 'daemon-reload'])
|
|
|
|
check_call(['systemctl', 'enable', '--no-pager', SERVICE])
|
|
|
|
check_call(['systemctl', 'restart', '--no-pager', SERVICE])
|
|
|
|
check_call(['systemctl', 'status', '--no-pager', SERVICE])
|