From 6617eab12ff6db6143fa43cc5bc3005aab2844a1 Mon Sep 17 00:00:00 2001 From: Wang Long Date: Wed, 16 Mar 2016 17:48:57 +0800 Subject: [PATCH 1/2] print proper tips when running `ros` or `system-docker` without using sudo `ros` and `system-docker` command requires user to be the root user, when we running them without using sudo, it will print the follow: [rancher@rancher ~]$ ros os list ERRO[0000] Failed to read /var/lib/rancher/conf/cloud-config.d: open /var/lib/rancher/conf/cloud-config.d: permission denied ERRO[0000] Error reading config files err=open /var/lib/rancher/conf/cloud-config.yml: permission denied files=[/var/lib/rancher/conf/cloud-config.yml] ERRO[0000] Failed [1/4] 25% ERRO[0000] Failed to load config ...... ...... FATA[0000] open /var/lib/rancher/conf/cloud-config.yml: permission denied and [rancher@rancher ~]$ system-docker restart docker Failed to kill container(docker): Cannot connect to the Docker daemon. Is the docker daemon running on this host? this patch make the tips more clear and simple. Signed-off-by: Wang Long --- cmd/control/cli.go | 7 +++++++ cmd/systemdocker/system-docker.go | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/cmd/control/cli.go b/cmd/control/cli.go index ec2ecc8b..d8c19eb2 100644 --- a/cmd/control/cli.go +++ b/cmd/control/cli.go @@ -3,6 +3,7 @@ package control import ( "os" + log "github.com/Sirupsen/logrus" "github.com/codegangsta/cli" "github.com/rancher/os/config" ) @@ -15,6 +16,12 @@ func Main() { app.Version = config.VERSION app.Author = "Rancher Labs, Inc." app.EnableBashCompletion = true + app.Before = func(c *cli.Context) error { + if os.Geteuid() != 0 { + log.Fatalf("%s: Need to be root", os.Args[0]) + } + return nil + } app.Commands = []cli.Command{ { diff --git a/cmd/systemdocker/system-docker.go b/cmd/systemdocker/system-docker.go index daa803bf..f925ecca 100644 --- a/cmd/systemdocker/system-docker.go +++ b/cmd/systemdocker/system-docker.go @@ -19,6 +19,10 @@ func Main() { newEnv = append(newEnv, "DOCKER_HOST="+config.DOCKER_SYSTEM_HOST) + if os.Geteuid() != 0 { + log.Fatalf("%s: Need to be root", os.Args[0]) + } + os.Args[0] = config.DOCKER_DIST_BIN if err := syscall.Exec(os.Args[0], os.Args, newEnv); err != nil { log.Fatal(err) From 445c510dee6aa3b720bc56f4e5cc7afa7dc6b3ef Mon Sep 17 00:00:00 2001 From: Wang Long Date: Wed, 16 Mar 2016 18:41:54 +0800 Subject: [PATCH 2/2] fix the testcase: add `sudo` to `ros dev` command Signed-off-by: Wang Long --- tests/integration/rostest/test_06_subdir.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/rostest/test_06_subdir.py b/tests/integration/rostest/test_06_subdir.py index cc665bd7..078f7640 100644 --- a/tests/integration/rostest/test_06_subdir.py +++ b/tests/integration/rostest/test_06_subdir.py @@ -14,6 +14,6 @@ def test_system_docker_survives_custom_docker_install(qemu): SSH(qemu).check_call('bash', '-c', ''' set -x -e mkdir x - sudo mount $(ros dev LABEL=RANCHER_STATE) x + sudo mount $(sudo ros dev LABEL=RANCHER_STATE) x [ -d x/ros_subdir/home/rancher ] '''.strip())