diff --git a/README.md b/README.md index 049c774..f08c647 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,8 @@ cp ground-control.sample.cfg ground-control.cfg ## Installation ``` -sudo ./install +./install +sudo loginctl enable-linger ``` ## Output diff --git a/ground-control.service b/ground-control.service index 3d1253b..259e07c 100644 --- a/ground-control.service +++ b/ground-control.service @@ -1,6 +1,6 @@ [Unit] Description=Ground Control -After=multi.user.target +After=network.online.target [Service] Type=simple @@ -8,7 +8,6 @@ WorkingDirectory=$workingDirectory ExecStart=$execStart Restart=on-failure SyslogIdentifier=ground-control -User=$user [Install] -WantedBy=multi-user.target +WantedBy=default.target diff --git a/install b/install index 27c9fbc..55b4596 100755 --- a/install +++ b/install @@ -9,11 +9,11 @@ from subprocess import check_output EXEC = 'ground-control.py' SERVICE = 'ground-control.service' -SYSTEM_DIR = '/etc/systemd/system' +SYSTEM_DIR = '~/.config/systemd/user' 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) +SERVICE_FILE = os.path.join(os.path.expanduser(SYSTEM_DIR), SERVICE) PYTHON = sys.executable EXEC_START = f'{PYTHON} {EXEC}' USER = check_output(['logname']).decode('utf-8').strip() @@ -23,14 +23,15 @@ with open(SERVICE_TEMPLATE) as f: serviceFile = serviceTemplate.substitute( workingDirectory=CURRENT_DIR, - execStart=EXEC_START, - user=USER + execStart=EXEC_START ) +os.makedirs(os.path.dirname(SERVICE_FILE), exist_ok=True) + 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]) +check_call(['systemctl', '--user', 'daemon-reload']) +check_call(['systemctl', '--user', 'enable', '--no-pager', SERVICE]) +check_call(['systemctl', '--user', 'restart', '--no-pager', SERVICE]) +check_call(['systemctl', '--user', 'status', '--no-pager', SERVICE])