32 lines
926 B
Python
Executable File
32 lines
926 B
Python
Executable File
#! /usr/bin/env python3
|
|
|
|
import os
|
|
from string import Template
|
|
from subprocess import check_call
|
|
|
|
EXEC = 'wifi-keepalive.py'
|
|
SERVICE = 'wifi-keepalive.service'
|
|
SYSTEM_DIR = '/etc/systemd/system'
|
|
|
|
CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
|
|
EXEC_PATH = os.path.join(CURRENT_DIR, EXEC)
|
|
SERVICE_TEMPLATE = os.path.join(CURRENT_DIR, SERVICE)
|
|
SERVICE_FILE = os.path.join(SYSTEM_DIR, SERVICE)
|
|
EXEC_START = f'python3 {EXEC}'
|
|
|
|
with open(SERVICE_TEMPLATE) as f:
|
|
serviceTemplate = Template(f.read())
|
|
|
|
serviceFile = serviceTemplate.substitute(
|
|
workingDirectory=CURRENT_DIR,
|
|
execStart=EXEC_START
|
|
)
|
|
|
|
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])
|