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

Proposed by Sergio Schvezov
Status: Merged
Approved by: Sergio Schvezov
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
Michael Vogt (community) Approve
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.
Revision history for this message
Michael Vogt (mvo) wrote :

+1

review: Approve
Revision history for this message
Sergio Schvezov (sergiusens) :
review: Approve
84. By Sergio Schvezov

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
=== modified file 'pkg/meta/hooks/config'
--- pkg/meta/hooks/config 2015-02-27 01:37:42 +0000
+++ pkg/meta/hooks/config 2015-02-27 16:36:26 +0000
@@ -3,11 +3,13 @@
33
4import configparser4import configparser
5import os5import os
6import subprocess
6import sys7import sys
7import yaml8import yaml
89
910
10WEBDM_DATA_PATH = os.environ['SNAP_APP_DATA_PATH']11WEBDM_DATA_PATH = os.environ['SNAP_APP_DATA_PATH']
12WEBDM_VERSION = os.environ['SNAP_VERSION']
11AVAHI_CONFIG_FILE = os.path.join(WEBDM_DATA_PATH, 'avahi-daemon.conf')13AVAHI_CONFIG_FILE = os.path.join(WEBDM_DATA_PATH, 'avahi-daemon.conf')
1214
13def main():15def main():
@@ -27,6 +29,8 @@
27def set_config(config_yaml):29def set_config(config_yaml):
28 """set_config sets a configuration and returns avahi_config"""30 """set_config sets a configuration and returns avahi_config"""
2931
32 restart_avahi = False
33
30 config = config_yaml['config']['webdm']34 config = config_yaml['config']['webdm']
3135
32 avahi_config = configparser.ConfigParser()36 avahi_config = configparser.ConfigParser()
@@ -34,6 +38,15 @@
3438
35 if 'avahi-hostname' in config:39 if 'avahi-hostname' in config:
36 avahi_config['server']['host-name'] = config['avahi-hostname']40 avahi_config['server']['host-name'] = config['avahi-hostname']
41 restart_avahi = True
42
43 if restart_avahi:
44 avahi_unit = 'webdm_avahi_%s.service' % WEBDM_VERSION
45 try:
46 subprocess.check_call(['systemctl', 'restart', avahi_unit])
47 except subprocess.CalledProcessError:
48 print("Cannot restart required services to fully apply "
49 "the configuration changes")
3750
38 return avahi_config51 return avahi_config
3952

Subscribers

People subscribed via source and target branches