Merge lp:~cjwatson/turku-charms/turku-agent-charm-fix-systemd-harder into lp:turku-charms/turku-agent-charm

Proposed by Colin Watson on 2019-07-17
Status: Merged
Approved by: Nick Moffitt on 2019-07-24
Approved revision: 15
Merged at revision: 15
Proposed branch: lp:~cjwatson/turku-charms/turku-agent-charm-fix-systemd-harder
Merge into: lp:turku-charms/turku-agent-charm
Diff against target: 41 lines (+17/-7)
1 file modified
hooks/hooks.py (+17/-7)
To merge this branch: bzr merge lp:~cjwatson/turku-charms/turku-agent-charm-fix-systemd-harder
Reviewer Review Type Date Requested Status
Turku Charmers 2019-07-17 Pending
Review via email: mp+370267@code.launchpad.net

Commit message

Fix installation of systemd units.

Description of the change

We only need to enable those units that have an [Install] section. Trying to enable the others does nothing except producing warnings. We also need to start the units that we've enabled.

To post a comment you must log in.

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Change successfully merged at revision 15

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/hooks.py'
2--- hooks/hooks.py 2019-07-04 23:42:09 +0000
3+++ hooks/hooks.py 2019-07-17 18:07:22 +0000
4@@ -28,6 +28,11 @@
5 return json.dumps(obj, sort_keys=True, indent=4, separators=(',', ': '))
6
7
8+def systemd_is_running():
9+ """Is systemd the running init daemon?"""
10+ return os.path.isdir('/run/systemd/system')
11+
12+
13 def install():
14 subprocess.check_call(['apt-get', 'update'])
15 subprocess.check_call(['apt-get', '-y', 'install', 'python3', 'python3-setuptools', 'python3-pkg-resources'])
16@@ -53,13 +58,18 @@
17 ):
18 shutil.copyfile(os.path.join('files/turku-agent', unit),
19 os.path.join('/etc/systemd/system', unit))
20- # Even if the directory exists, Systemd may not be installed or
21- # enabled. So don't fail on this systemctl command.
22- try:
23- subprocess.call(['systemctl', 'enable', unit])
24- except OSError as e:
25- if e.errno != 2:
26- raise
27+
28+ # Enable and start units. We only need to operate on those units
29+ # that have [Install] sections; the others are activated on demand.
30+ if systemd_is_running():
31+ installable_units = [
32+ 'turku-agent-ping.timer',
33+ 'turku-agent-rsyncd.service',
34+ 'turku-update-config.timer',
35+ ]
36+ subprocess.call(['systemctl', 'enable'] + installable_units)
37+ subprocess.call(['systemctl', 'daemon-reload'])
38+ subprocess.call(['systemctl', 'start'] + installable_units)
39
40
41 def configure(juju_stored=None):

Subscribers

People subscribed via source and target branches

to all changes: