linux: change ifs to switches.
This commit is contained in:
+18
-17
@@ -19,11 +19,10 @@ const (
|
|||||||
|
|
||||||
func getFlavor() initFlavor {
|
func getFlavor() initFlavor {
|
||||||
flavor := initSystemV
|
flavor := initSystemV
|
||||||
if isUpstart() {
|
|
||||||
flavor = initUpstart
|
|
||||||
}
|
|
||||||
if isSystemd() {
|
if isSystemd() {
|
||||||
flavor = initSystemd
|
flavor = initSystemd
|
||||||
|
} else if isUpstart() {
|
||||||
|
flavor = initUpstart
|
||||||
}
|
}
|
||||||
return flavor
|
return flavor
|
||||||
}
|
}
|
||||||
@@ -82,12 +81,12 @@ func (f initFlavor) String() string {
|
|||||||
|
|
||||||
func (f initFlavor) ConfigPath(name string) string {
|
func (f initFlavor) ConfigPath(name string) string {
|
||||||
switch f {
|
switch f {
|
||||||
|
case initSystemd:
|
||||||
|
return "/etc/systemd/system/" + name + ".service"
|
||||||
case initSystemV:
|
case initSystemV:
|
||||||
return "/etc/init.d/" + name
|
return "/etc/init.d/" + name
|
||||||
case initUpstart:
|
case initUpstart:
|
||||||
return "/etc/init/" + name + ".conf"
|
return "/etc/init/" + name + ".conf"
|
||||||
case initSystemd:
|
|
||||||
return "/etc/systemd/system/" + name + ".service"
|
|
||||||
default:
|
default:
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@@ -96,12 +95,12 @@ func (f initFlavor) ConfigPath(name string) string {
|
|||||||
func (f initFlavor) GetTemplate() *template.Template {
|
func (f initFlavor) GetTemplate() *template.Template {
|
||||||
var templ string
|
var templ string
|
||||||
switch f {
|
switch f {
|
||||||
|
case initSystemd:
|
||||||
|
templ = systemdScript
|
||||||
case initSystemV:
|
case initSystemV:
|
||||||
templ = systemVScript
|
templ = systemVScript
|
||||||
case initUpstart:
|
case initUpstart:
|
||||||
templ = upstartScript
|
templ = upstartScript
|
||||||
case initSystemd:
|
|
||||||
templ = systemdScript
|
|
||||||
}
|
}
|
||||||
return template.Must(template.New(f.String() + "Script").Parse(templ))
|
return template.Must(template.New(f.String() + "Script").Parse(templ))
|
||||||
}
|
}
|
||||||
@@ -191,23 +190,25 @@ func (s *linuxService) Run(onStart, onStop func() error) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *linuxService) Start() error {
|
func (s *linuxService) Start() error {
|
||||||
if s.flavor == initUpstart {
|
switch s.flavor {
|
||||||
return exec.Command("initctl", "start", s.name).Run()
|
case initSystemd:
|
||||||
}
|
|
||||||
if s.flavor == initSystemd {
|
|
||||||
return exec.Command("systemctl", "start", s.name+".service").Run()
|
return exec.Command("systemctl", "start", s.name+".service").Run()
|
||||||
|
case initUpstart:
|
||||||
|
return exec.Command("initctl", "start", s.name).Run()
|
||||||
|
default:
|
||||||
|
return exec.Command("service", s.name, "start").Run()
|
||||||
}
|
}
|
||||||
return exec.Command("service", s.name, "start").Run()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *linuxService) Stop() error {
|
func (s *linuxService) Stop() error {
|
||||||
if s.flavor == initUpstart {
|
switch s.flavor {
|
||||||
return exec.Command("initctl", "stop", s.name).Run()
|
case initSystemd:
|
||||||
}
|
|
||||||
if s.flavor == initSystemd {
|
|
||||||
return exec.Command("systemctl", "stop", s.name+".service").Run()
|
return exec.Command("systemctl", "stop", s.name+".service").Run()
|
||||||
|
case initUpstart:
|
||||||
|
return exec.Command("initctl", "stop", s.name).Run()
|
||||||
|
default:
|
||||||
|
return exec.Command("service", s.name, "stop").Run()
|
||||||
}
|
}
|
||||||
return exec.Command("service", s.name, "stop").Run()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *linuxService) Error(format string, a ...interface{}) error {
|
func (s *linuxService) Error(format string, a ...interface{}) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user