Merge lp:~ogra/core-snap/more-flexible-service-handling into lp:core-snap

Proposed by Oliver Grawert on 2017-02-01
Status: Merged
Merged at revision: 48
Proposed branch: lp:~ogra/core-snap/more-flexible-service-handling
Merge into: lp:core-snap
Diff against target: 55 lines (+17/-12)
1 file modified
hooks/configure (+17/-12)
To merge this branch: bzr merge lp:~ogra/core-snap/more-flexible-service-handling
Reviewer Review Type Date Requested Status
Simon Fels (community) Approve on 2017-02-01
Gustavo Niemeyer Approve on 2017-02-01
Michael Vogt 2017-02-01 Pending
Review via email: mp+316116@code.launchpad.net

Description of the Change

make the configure hook code more flexible for managing services, add rsyslog to the manageable services.

a list of possible service names to be added to the SERVICES variable can be obtained via:

systemctl |grep .service|cut -d ' ' -f1|sed 's/.service$//'

To post a comment you must log in.
Gustavo Niemeyer (niemeyer) wrote :

LGTM

review: Approve
Simon Fels (morphis) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/configure'
2--- hooks/configure 2017-01-27 16:22:08 +0000
3+++ hooks/configure 2017-02-01 14:03:27 +0000
4@@ -14,17 +14,20 @@
5 # You should have received a copy of the GNU General Public License
6 # along with this program. If not, see <http://www.gnu.org/licenses/>.
7
8-switch_service_ssh() {
9+# list services we can disable and enable
10+SERVICES="ssh rsyslog"
11+
12+switch_service() {
13 case "$1" in
14 false)
15 # When the unit is already enabled but not active a call with
16 # --now does start the unit so we have to check for that case
17 # and explicitly start the unit.
18- if [ "$(systemctl is-enabled ssh.service)" = "disabled" ]; then
19- systemctl enable ssh.service
20+ if [ "$(systemctl is-enabled $2.service)" = "disabled" ]; then
21+ systemctl enable $2.service
22 fi
23- if [ "$(systemctl is-active ssh.service)" = "inactive" ]; then
24- systemctl start ssh.service
25+ if [ "$(systemctl is-active $2.service)" = "inactive" ]; then
26+ systemctl start $2.service
27 fi
28 ;;
29 true)
30@@ -32,16 +35,18 @@
31 # and fails with an error message. Because of that we're going
32 # in two steps here and disable first and then stopping the
33 # service unit.
34- systemctl disable ssh.service
35- systemctl stop ssh.service
36+ systemctl disable $2.service
37+ systemctl stop $2.service
38 ;;
39 *)
40- echo "ERROR: Invalid value '$1' provided for option service.ssh.disable"
41+ echo "ERROR: Invalid value '$1' provided for option service.$2.disable"
42 exit 1
43 esac
44 }
45
46-value=$(snapctl get service.ssh.disable)
47-if [ -n "$value" ]; then
48- switch_service_ssh $value
49-fi
50+for service in $SERVICES; do
51+ value=$(snapctl get service.$service.disable)
52+ if [ -n "$value" ]; then
53+ switch_service $value $service
54+ fi
55+done

Subscribers

People subscribed via source and target branches