Skip to content

Commit a187512

Browse files
author
Tim McNamara
committed
Refactor snap support from service package
1 parent 1946895 commit a187512

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

mongo/service.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,14 @@ type mongoService interface {
8484
}
8585

8686
var newService = func(name string, conf common.Conf) (mongoService, error) {
87+
if featureflag.Enabled(feature.MongoDbSnap) {
88+
return snap.NewServiceFromName(name, conf)
89+
}
8790
return service.DiscoverService(name, conf)
8891
}
8992

9093
var discoverService = func(name string) (mongoService, error) {
91-
return service.DiscoverService(name, common.Conf{})
94+
return newService(name, common.Conf{})
9295
}
9396

9497
// IsServiceInstalled returns whether the MongoDB init service

service/discovery.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515

1616
"github.com/juju/juju/feature"
1717
"github.com/juju/juju/service/common"
18-
"github.com/juju/juju/service/snap"
1918
"github.com/juju/juju/service/systemd"
2019
"github.com/juju/juju/service/upstart"
2120
"github.com/juju/juju/service/windows"
@@ -107,13 +106,6 @@ var discoveryFuncs = []discoveryCheck{
107106
}
108107

109108
func discoverLocalInitSystem() (string, error) {
110-
if featureflag.Enabled(feature.MongoDbSnap) {
111-
local, err := snap.IsRunning()
112-
if err == nil && local {
113-
return InitSystemSnap, nil
114-
}
115-
return "", errors.NotFoundf("snap does not appear to be installed correctly")
116-
}
117109
for _, check := range discoveryFuncs {
118110
local, err := check.isRunning()
119111
if err != nil {
@@ -129,7 +121,6 @@ func discoverLocalInitSystem() (string, error) {
129121
}
130122

131123
const (
132-
discoverSnap = "if [ -x /usr/bin/snap ] || [ -d /snap ]; then echo -n snap; exit 0; fi"
133124
discoverSystemd = "if [ -d /run/systemd/system ]; then echo -n systemd; exit 0; fi"
134125
discoverUpstart = "if [ -f /sbin/initctl ] && /sbin/initctl --system list 2>&1 > /dev/null; then echo -n upstart; exit 0; fi"
135126
)
@@ -144,9 +135,6 @@ func DiscoverInitSystemScript() string {
144135
discoverUpstart,
145136
"exit 1",
146137
}
147-
if featureflag.Enabled(feature.MongoDbSnap) {
148-
tests = append([]string{discoverSnap}, tests...)
149-
}
150138
data := renderer.RenderScript(tests)
151139
return string(data)
152140
}

0 commit comments

Comments
 (0)