forked from MarcelWaldvogel/chrony-graph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall
executable file
·43 lines (34 loc) · 1.29 KB
/
install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#! /usr/bin/env python3
import os
import shutil
from string import Template
from subprocess import check_call
from subprocess import check_output
EXEC = 'chrony-graph-loop'
SERVICE = 'chrony-graph.service'
SYSTEM_DIR = '/etc/systemd/system'
CONFIG = 'chrony-graph.conf'
SAMPLE_CONFIG = 'chrony-graph.sample.conf'
CONFIG_DIR = '/etc/chrony-graph'
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)
CONFIG_FILE = os.path.join(CONFIG_DIR, CONFIG)
USER = check_output(['logname']).decode('utf-8').strip()
with open(SERVICE_TEMPLATE) as f:
serviceTemplate = Template(f.read())
serviceFile = serviceTemplate.substitute(
workingDirectory=CURRENT_DIR,
execStart=EXEC_PATH,
user=USER
)
with open(SERVICE_FILE, 'w') as f:
f.write(serviceFile)
if not os.path.exists(CONFIG_FILE):
os.makedirs(CONFIG_DIR, exist_ok=True)
shutil.copy(SAMPLE_CONFIG, CONFIG_FILE)
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])