Install at the user level

This commit is contained in:
Mike Cifelli 2024-04-04 09:43:44 -04:00
parent 9593d77e10
commit 0b21da8145
Signed by: mike
GPG Key ID: 6B08C6BE47D08E4C
3 changed files with 13 additions and 12 deletions

View File

@ -9,7 +9,8 @@ cp ground-control.sample.cfg ground-control.cfg
## Installation ## Installation
``` ```
sudo ./install ./install
sudo loginctl enable-linger <user>
``` ```
## Output ## Output

View File

@ -1,6 +1,6 @@
[Unit] [Unit]
Description=Ground Control Description=Ground Control
After=multi.user.target After=network.online.target
[Service] [Service]
Type=simple Type=simple
@ -8,7 +8,6 @@ WorkingDirectory=$workingDirectory
ExecStart=$execStart ExecStart=$execStart
Restart=on-failure Restart=on-failure
SyslogIdentifier=ground-control SyslogIdentifier=ground-control
User=$user
[Install] [Install]
WantedBy=multi-user.target WantedBy=default.target

17
install
View File

@ -9,11 +9,11 @@ from subprocess import check_output
EXEC = 'ground-control.py' EXEC = 'ground-control.py'
SERVICE = 'ground-control.service' SERVICE = 'ground-control.service'
SYSTEM_DIR = '/etc/systemd/system' SYSTEM_DIR = '~/.config/systemd/user'
CURRENT_DIR = os.path.dirname(os.path.realpath(__file__)) CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
SERVICE_TEMPLATE = os.path.join(CURRENT_DIR, SERVICE) SERVICE_TEMPLATE = os.path.join(CURRENT_DIR, SERVICE)
SERVICE_FILE = os.path.join(SYSTEM_DIR, SERVICE) SERVICE_FILE = os.path.join(os.path.expanduser(SYSTEM_DIR), SERVICE)
PYTHON = sys.executable PYTHON = sys.executable
EXEC_START = f'{PYTHON} {EXEC}' EXEC_START = f'{PYTHON} {EXEC}'
USER = check_output(['logname']).decode('utf-8').strip() USER = check_output(['logname']).decode('utf-8').strip()
@ -23,14 +23,15 @@ with open(SERVICE_TEMPLATE) as f:
serviceFile = serviceTemplate.substitute( serviceFile = serviceTemplate.substitute(
workingDirectory=CURRENT_DIR, workingDirectory=CURRENT_DIR,
execStart=EXEC_START, execStart=EXEC_START
user=USER
) )
os.makedirs(os.path.dirname(SERVICE_FILE), exist_ok=True)
with open(SERVICE_FILE, 'w') as f: with open(SERVICE_FILE, 'w') as f:
f.write(serviceFile) f.write(serviceFile)
check_call(['systemctl', 'daemon-reload']) check_call(['systemctl', '--user', 'daemon-reload'])
check_call(['systemctl', 'enable', '--no-pager', SERVICE]) check_call(['systemctl', '--user', 'enable', '--no-pager', SERVICE])
check_call(['systemctl', 'restart', '--no-pager', SERVICE]) check_call(['systemctl', '--user', 'restart', '--no-pager', SERVICE])
check_call(['systemctl', 'status', '--no-pager', SERVICE]) check_call(['systemctl', '--user', 'status', '--no-pager', SERVICE])