func getDefaultConfigDirectory() string { if os.Getuid() == 0 { return "/etc/gitlab-runner" } else if homeDir := helpers.GetHomeDir(); homeDir != "" { return filepath.Join(homeDir, ".gitlab-runner") } else if currentDir := helpers.GetCurrentWorkingDirectory(); currentDir != "" { return currentDir } panic("Cannot get default config file location") }
func init() { flags := []cli.Flag{ cli.StringFlag{ Name: "service, n", Value: defaultServiceName, Usage: "Specify service name to use", }, } installFlags := flags installFlags = append(installFlags, cli.StringFlag{ Name: "working-directory, d", Value: helpers.GetCurrentWorkingDirectory(), Usage: "Specify custom root directory where all data are stored", }) installFlags = append(installFlags, cli.StringFlag{ Name: "config, c", Value: getDefaultConfigFile(), Usage: "Specify custom config file", }) if runtime.GOOS == "windows" { installFlags = append(installFlags, cli.StringFlag{ Name: "user, u", Value: "", Usage: "Specify user-name to secure the runner", }) installFlags = append(installFlags, cli.StringFlag{ Name: "password, p", Value: "", Usage: "Specify user password to install service (required)", }) } else if os.Getuid() == 0 { installFlags = append(installFlags, cli.StringFlag{ Name: "user, u", Value: "", Usage: "Specify user-name to secure the runner", }) } common.RegisterCommand(cli.Command{ Name: "install", Usage: "install service", Action: RunServiceControl, Flags: installFlags, }) common.RegisterCommand(cli.Command{ Name: "uninstall", Usage: "uninstall service", Action: RunServiceControl, Flags: flags, }) common.RegisterCommand(cli.Command{ Name: "start", Usage: "start service", Action: RunServiceControl, Flags: flags, }) common.RegisterCommand(cli.Command{ Name: "stop", Usage: "stop service", Action: RunServiceControl, Flags: flags, }) common.RegisterCommand(cli.Command{ Name: "restart", Usage: "restart service", Action: RunServiceControl, Flags: flags, }) common.RegisterCommand(cli.Command{ Name: "status", Usage: "get status of a service", Action: RunServiceControl, Flags: flags, }) }