Merge lp:~sergiusens/snapweb/restartConfigHook into lp:~snappy-dev/snapweb/trunk

Proposed by Sergio Schvezov on 2015-02-27
Status: Merged
Approved by: Sergio Schvezov on 2015-02-27
Approved revision: no longer in the source branch.
Merged at revision: 84
Proposed branch: lp:~sergiusens/snapweb/restartConfigHook
Merge into: lp:~snappy-dev/snapweb/trunk
Prerequisite: lp:~sergiusens/snapweb/addConfigSupport
Diff against target: 41 lines (+13/-0)
1 file modified
pkg/meta/hooks/config (+13/-0)
To merge this branch: bzr merge lp:~sergiusens/snapweb/restartConfigHook
Reviewer Review Type Date Requested Status
Sergio Schvezov Approve on 2015-02-27
Michael Vogt 2015-02-27 Approve on 2015-02-27
Review via email: mp+251283@code.launchpad.net

Commit message

Support restart the service from the hook

To post a comment you must log in.
Michael Vogt (mvo) wrote :

+1

review: Approve
review: Approve
84. By Sergio Schvezov on 2015-02-27

Support restart the service from the hook by sergiusens approved by sergiusens,mvo

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'pkg/meta/hooks/config'
2--- pkg/meta/hooks/config 2015-02-27 01:37:42 +0000
3+++ pkg/meta/hooks/config 2015-02-27 16:36:26 +0000
4@@ -3,11 +3,13 @@
5
6 import configparser
7 import os
8+import subprocess
9 import sys
10 import yaml
11
12
13 WEBDM_DATA_PATH = os.environ['SNAP_APP_DATA_PATH']
14+WEBDM_VERSION = os.environ['SNAP_VERSION']
15 AVAHI_CONFIG_FILE = os.path.join(WEBDM_DATA_PATH, 'avahi-daemon.conf')
16
17 def main():
18@@ -27,6 +29,8 @@
19 def set_config(config_yaml):
20 """set_config sets a configuration and returns avahi_config"""
21
22+ restart_avahi = False
23+
24 config = config_yaml['config']['webdm']
25
26 avahi_config = configparser.ConfigParser()
27@@ -34,6 +38,15 @@
28
29 if 'avahi-hostname' in config:
30 avahi_config['server']['host-name'] = config['avahi-hostname']
31+ restart_avahi = True
32+
33+ if restart_avahi:
34+ avahi_unit = 'webdm_avahi_%s.service' % WEBDM_VERSION
35+ try:
36+ subprocess.check_call(['systemctl', 'restart', avahi_unit])
37+ except subprocess.CalledProcessError:
38+ print("Cannot restart required services to fully apply "
39+ "the configuration changes")
40
41 return avahi_config
42

Subscribers

People subscribed via source and target branches