Install at the user level
This commit is contained in:
parent
9593d77e10
commit
0b21da8145
|
@ -9,7 +9,8 @@ cp ground-control.sample.cfg ground-control.cfg
|
|||
|
||||
## Installation
|
||||
```
|
||||
sudo ./install
|
||||
./install
|
||||
sudo loginctl enable-linger <user>
|
||||
```
|
||||
|
||||
## Output
|
||||
|
|
|
@ -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
|
||||
|
|
17
install
17
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])
|
||||
|
|
Loading…
Reference in New Issue