Commit 9ade9673 authored by Kamil Trzciński's avatar Kamil Trzciński 🔴

Pass service name as argument during service installation

parent cd0d69ec
......@@ -7,8 +7,8 @@ import (
"syscall"
"time"
service "github.com/ayufan/golang-kardianos-service"
"github.com/codegangsta/cli"
"github.com/kardianos/service"
log "github.com/Sirupsen/logrus"
......@@ -375,10 +375,17 @@ func (mr *MultiRunner) Stop(s service.Service) error {
}
func CreateService(c *cli.Context) service.Service {
serviceName := c.String("service-name")
displayName := c.String("service-name")
if serviceName == "" {
serviceName = defaultServiceName
displayName = defaultDisplayName
}
svcConfig := &service.Config{
Name: "gitlab-ci-multi-runner",
DisplayName: "GitLab-CI Multi-purpose Runner",
Description: "Unofficial GitLab CI runner written in Go",
Name: serviceName,
DisplayName: displayName,
Description: defaultDescription,
Arguments: []string{"run"},
}
......@@ -441,6 +448,11 @@ func init() {
Usage: "API listen address, eg. :8080",
EnvVar: "API_LISTEN",
},
cli.StringFlag{
Name: "service-name, n",
Value: "",
Usage: "Use different names for different services",
},
},
})
}
......@@ -3,13 +3,19 @@ package commands
import (
log "github.com/Sirupsen/logrus"
"github.com/ayufan/gitlab-ci-multi-runner/common"
service "github.com/ayufan/golang-kardianos-service"
"github.com/codegangsta/cli"
"github.com/kardianos/service"
"os"
"os/user"
"runtime"
)
const (
defaultServiceName = "gitlab-ci-multi-runner"
defaultDisplayName = "GitLab-CI Multi-purpose Runner"
defaultDescription = "Unofficial GitLab CI runner written in Go"
)
type ServiceLogHook struct {
service.Logger
}
......@@ -51,14 +57,14 @@ func RunServiceControl(c *cli.Context) {
serviceName := c.String("service-name")
displayName := c.String("service-name")
if serviceName == "" {
serviceName = "gitlab-ci-multi-runner"
displayName = "GitLab-CI Multi-purpose Runner"
serviceName = defaultServiceName
displayName = defaultDisplayName
}
svcConfig := &service.Config{
Name: serviceName,
DisplayName: displayName,
Description: "Unofficial GitLab CI runner written in Go",
Description: defaultDescription,
Arguments: []string{"run"},
UserName: c.String("user"),
}
......@@ -80,6 +86,10 @@ func RunServiceControl(c *cli.Context) {
svcConfig.Arguments = append(svcConfig.Arguments, "--config", config)
}
if sn := c.String("service-name"); sn != "" {
svcConfig.Arguments = append(svcConfig.Arguments, "--service-name", sn)
}
s, err := service.New(&NullService{}, svcConfig)
if err != nil {
log.Fatal(err)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment