1
0
mirror of https://github.com/rancher/os.git synced 2025-06-26 06:51:40 +00:00
os/cmd/control/cli.go
Wang Long 6617eab12f 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 <long.wanglong@huawei.com>
2016-03-16 17:50:54 +08:00

69 lines
1.3 KiB
Go

package control
import (
"os"
log "github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
"github.com/rancher/os/config"
)
func Main() {
app := cli.NewApp()
app.Name = os.Args[0]
app.Usage = "Control and configure RancherOS"
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{
{
Name: "config",
ShortName: "c",
Usage: "configure settings",
HideHelp: true,
Subcommands: configSubcommands(),
},
{
Name: "dev",
ShortName: "d",
Usage: "dev spec",
HideHelp: true,
SkipFlagParsing: true,
Action: devAction,
},
{
Name: "env",
ShortName: "e",
Usage: "env command",
HideHelp: true,
SkipFlagParsing: true,
Action: envAction,
},
serviceCommand(),
{
Name: "os",
Usage: "operating system upgrade/downgrade",
HideHelp: true,
Subcommands: osSubcommands(),
},
{
Name: "tls",
Usage: "setup tls configuration",
HideHelp: true,
Subcommands: tlsConfCommands(),
},
installCommand,
selinuxCommand(),
}
app.Run(os.Args)
}