From 5180c7e937ff2606a2e214f2a6270dd14aaa536c Mon Sep 17 00:00:00 2001 From: Wang Long Date: Fri, 8 Apr 2016 19:00:24 +0800 Subject: [PATCH] Check the validity of the service name if user want to switch to `ubuntu-console` and type the wrong service name `ubuntu-consile`, the command `sudo ros service enable ubuntu-consile` run with no error. after the reboot, the console is still the busybox console. It is better to Warn user that the `ubuntu-consile` is no a valid service name. This patch also check the validity of the service name when disable and delete service. Signed-off-by: Wang Long --- cmd/control/service.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cmd/control/service.go b/cmd/control/service.go index 2f48f057..cc023764 100644 --- a/cmd/control/service.go +++ b/cmd/control/service.go @@ -95,7 +95,7 @@ func disable(c *cli.Context) { for _, service := range c.Args() { if _, ok := cfg.Rancher.ServicesInclude[service]; !ok { - continue + logrus.Fatalf("ERROR: Service %s is not a valid service, use \"sudo ros service list\" to list the services", service) } cfg.Rancher.ServicesInclude[service] = false @@ -118,7 +118,7 @@ func del(c *cli.Context) { for _, service := range c.Args() { if _, ok := cfg.Rancher.ServicesInclude[service]; !ok { - continue + logrus.Fatalf("ERROR: Service %s is not a valid service, use \"sudo ros service list\" to list the services", service) } delete(cfg.Rancher.ServicesInclude, service) changed = true @@ -137,6 +137,11 @@ func enable(c *cli.Context) { logrus.Fatal(err) } + services, err := util.GetServices(cfg.Rancher.Repositories.ToArray()) + if err != nil { + logrus.Fatalf("Failed to get services: %v", err) + } + var enabledServices []string for _, service := range c.Args() { @@ -145,6 +150,10 @@ func enable(c *cli.Context) { logrus.Fatalf("ERROR: Service should be in path /var/lib/rancher/conf") } + if !util.Contains(services, service) { + logrus.Fatalf("ERROR: Service %s is not a valid service, use \"sudo ros service list\" to list the services", service) + } + cfg.Rancher.ServicesInclude[service] = true enabledServices = append(enabledServices, service) }