Skip to content
This repository
Browse code

Remove everything CLI-related

  • Loading branch information...
commit 42404636b9dd21d282da65c2bcb27a71fd7084d5 1 parent d5ae02a
Alexis Sellier authored December 05, 2012
56  Makefile
... ...
@@ -1,59 +1,9 @@
1 1
 MAJOR    := 0
2  
-MINOR    := 7
3  
-PATCH    := 4
  2
+MINOR    := 8
  3
+PATCH    := 0
4 4
 VERSION  := $(MAJOR).$(MINOR).$(PATCH)
5  
-GOPATH   ?= $(PWD)
6  
-GOBIN    ?= $(GOPATH)/bin
7 5
 LDFLAGS  := -ldflags "-X main.VERSION $(VERSION)"
8  
-GOFLAGS  := -x $(LDFLAGS)
9  
-PKGPATH  := $(GOPATH)/src/github.com/soundcloud/visor
10  
-GOARCH   ?= amd64
11  
-
12  
-# LOCAL #
13 6
 
14 7
 default:
15  
-	@go build $(LDFLAGS) ./cmd/visor
16  
-	@echo built ./visor v$(VERSION)
17  
-
18  
-install: $(PKGPATH)
19  
-	GOPATH=$(GOPATH) go get $(GOFLAGS) -d ./cmd/visor
20  
-	GOPATH=$(GOPATH) GOBIN=$(GOBIN) go install $(GOFLAGS) ./cmd/visor
21  
-	@echo "built $(GOBIN)/visor v$(VERSION)"
22  
-
23  
-$(PKGPATH):
24  
-	mkdir -p $(shell dirname $(PKGPATH))
25  
-	ln -sf $(PWD) $(PKGPATH)
26  
-
27  
-test:
28  
-	go test
29  
-
30  
-# DIST #
31  
-
32  
-dist: linux darwin
33  
-
34  
-linux darwin:
35  
-	GOOS=$@ CGO_ENABLED=0 GOARCH=$(GOARCH) go build $(LDFLAGS) -o bin/$@/visor ./cmd/visor
36  
-	cd bin/$@ && tar -caf visor-v$(VERSION)-$@.tar.gz visor
37  
-
38  
-# DEBIAN PACKAGING #
39  
-
40  
-DEB_NAME=visor
41  
-DEB_URL=http://github.com/soundcloud/visor
42  
-DEB_VERSION=$(VERSION)
43  
-DEB_DESCRIPTION=A command line interface for visor
44  
-DEB_MAINTAINER=Daniel Bornkessel <daniel@soundcloud.com>
45  
-
46  
-include deb.mk
47  
-
48  
-debroot:
49  
-	GOBIN=$(DEB_ROOT)/usr/bin $(MAKE) install
50  
-
51  
-# BUILD #
52  
-
53  
-build: clean debroot debbuild
54  
-
55  
-clean: debclean
56  
-	GOPATH=$(GOPATH) go clean
57  
-	rm -rf bin src pkg
  8
+	go build $(LDFLAGS)
58 9
 
59  
-.PHONY: test
10  README.md
Source Rendered
@@ -122,16 +122,6 @@ func main() {
122 122
         ./make.sh
123 123
         go install
124 124
 
125  
-#### Installation
126  
-
127  
-Debian in our internal network:
128  
-
129  
-    apt-get install visor
130  
-
131  
-Compile yourself:
132  
-
133  
- * install [golang](http://golang.org) and `make install`
134  
-
135 125
 ### Testing
136 126
 
137 127
 First start `doozerd` with default configuration. Then run:
44  cmd/visor/app-describe.go
... ...
@@ -1,44 +0,0 @@
1  
-// Copyright (c) 2012, SoundCloud Ltd.
2  
-// Use of this source code is governed by a BSD-style
3  
-// license that can be found in the LICENSE file.
4  
-// Source code and contact info at http://github.com/soundcloud/visor
5  
-
6  
-package main
7  
-
8  
-import (
9  
-	"fmt"
10  
-	"github.com/soundcloud/visor"
11  
-	"os"
12  
-)
13  
-
14  
-var cmdAppDescribe = &Command{
15  
-	Name:      "app-describe",
16  
-	Short:     "shows app info",
17  
-	UsageLine: "app-describe <name>",
18  
-	Long: `
19  
-App-describe returns meta information for the appliation given.
20  
-  `,
21  
-}
22  
-
23  
-func init() {
24  
-	cmdAppDescribe.Run = runAppDescribe
25  
-}
26  
-
27  
-func runAppDescribe(cmd *Command, args []string) {
28  
-	if len(args) < 1 {
29  
-		cmd.Flag.Usage()
30  
-	}
31  
-
32  
-	s := cmdAppDescribe.Snapshot
33  
-
34  
-	app, err := visor.GetApp(s, args[0])
35  
-	if err != nil {
36  
-		fmt.Fprintf(os.Stderr, "Error fetching app %s\n", err.Error())
37  
-		os.Exit(1)
38  
-	}
39  
-
40  
-	fmt.Fprintf(os.Stdout, "name: %s\n", app.Name)
41  
-	fmt.Fprintf(os.Stdout, "type: %s\n", app.DeployType)
42  
-	fmt.Fprintf(os.Stdout, "repo: %s\n", app.RepoUrl)
43  
-	fmt.Fprintf(os.Stdout, "stack: %s\n", app.Stack)
44  
-}
47  cmd/visor/app-env-del.go
... ...
@@ -1,47 +0,0 @@
1  
-// Copyright (c) 2012, SoundCloud Ltd.
2  
-// Use of this source code is governed by a BSD-style
3  
-// license that can be found in the LICENSE file.
4  
-// Source code and contact info at http://github.com/soundcloud/visor
5  
-
6  
-package main
7  
-
8  
-import (
9  
-	"fmt"
10  
-	"github.com/soundcloud/visor"
11  
-	"os"
12  
-)
13  
-
14  
-var cmdAppEnvDel = &Command{
15  
-	Name:      "app-env-del",
16  
-	Short:     "delete environment variable",
17  
-	UsageLine: "app-env-del <app> <key>",
18  
-	Long: `
19  
-App-env-del removes a value for the given key in the application environment.
20  
-  `,
21  
-}
22  
-
23  
-func init() {
24  
-	cmdAppEnvDel.Run = runAppEnvDel
25  
-}
26  
-
27  
-func runAppEnvDel(cmd *Command, args []string) {
28  
-	if len(args) < 2 {
29  
-		cmd.Flag.Usage()
30  
-	}
31  
-
32  
-	s := cmdAppEnvDel.Snapshot
33  
-	name := args[0]
34  
-	key := args[1]
35  
-
36  
-	app, err := visor.GetApp(s, name)
37  
-	if err != nil {
38  
-		fmt.Fprintf(os.Stderr, "Error fetching app %s\n", err.Error())
39  
-		os.Exit(1)
40  
-	}
41  
-
42  
-	_, err = app.DelEnvironmentVar(key)
43  
-	if err != nil {
44  
-		fmt.Fprintf(os.Stderr, "Error removing env var %s\n", err.Error())
45  
-		os.Exit(1)
46  
-	}
47  
-}
61  cmd/visor/app-env-get.go
... ...
@@ -1,61 +0,0 @@
1  
-// Copyright (c) 2012, SoundCloud Ltd.
2  
-// Use of this source code is governed by a BSD-style
3  
-// license that can be found in the LICENSE file.
4  
-// Source code and contact info at http://github.com/soundcloud/visor
5  
-
6  
-package main
7  
-
8  
-import (
9  
-	"fmt"
10  
-	"github.com/soundcloud/visor"
11  
-	"os"
12  
-)
13  
-
14  
-var cmdAppEnvGet = &Command{
15  
-	Name:      "app-env-get",
16  
-	Short:     "retrieve environment",
17  
-	UsageLine: "app-env-get <app> [key]",
18  
-	Long: `
19  
-App-env-get returns the whole or filtered environment for an application.
20  
-  `,
21  
-}
22  
-
23  
-func init() {
24  
-	cmdAppEnvGet.Run = runAppEnvGet
25  
-}
26  
-
27  
-func runAppEnvGet(cmd *Command, args []string) {
28  
-	if len(args) < 1 {
29  
-		cmd.Flag.Usage()
30  
-	}
31  
-
32  
-	s := cmdAppEnvGet.Snapshot
33  
-	name := args[0]
34  
-
35  
-	app, err := visor.GetApp(s, name)
36  
-	if err != nil {
37  
-		fmt.Fprintf(os.Stderr, "Error fetching app %s\n", err.Error())
38  
-		os.Exit(1)
39  
-	}
40  
-
41  
-	if len(args) == 2 {
42  
-		key := args[1]
43  
-		val, err := app.GetEnvironmentVar(key)
44  
-		if err != nil {
45  
-			fmt.Fprintf(os.Stderr, "Error fetching app env %s\n", err.Error())
46  
-			os.Exit(1)
47  
-		}
48  
-
49  
-		fmt.Fprintf(os.Stdout, "%s=%s\n", key, val)
50  
-	} else {
51  
-		env, err := app.EnvironmentVars()
52  
-		if err != nil {
53  
-			fmt.Fprintf(os.Stderr, "Error fetching app env %s\n", err.Error())
54  
-			os.Exit(1)
55  
-		}
56  
-
57  
-		for key, val := range env {
58  
-			fmt.Fprintf(os.Stdout, "%s=%s\n", key, val)
59  
-		}
60  
-	}
61  
-}
48  cmd/visor/app-env-set.go
... ...
@@ -1,48 +0,0 @@
1  
-// Copyright (c) 2012, SoundCloud Ltd.
2  
-// Use of this source code is governed by a BSD-style
3  
-// license that can be found in the LICENSE file.
4  
-// Source code and contact info at http://github.com/soundcloud/visor
5  
-
6  
-package main
7  
-
8  
-import (
9  
-	"fmt"
10  
-	"github.com/soundcloud/visor"
11  
-	"os"
12  
-)
13  
-
14  
-var cmdAppEnvSet = &Command{
15  
-	Name:      "app-env-set",
16  
-	Short:     "store environment variable",
17  
-	UsageLine: "app-env-set <app> <key> <value>",
18  
-	Long: `
19  
-App-env-set stores a value for the given key in the application environment.
20  
-  `,
21  
-}
22  
-
23  
-func init() {
24  
-	cmdAppEnvSet.Run = runAppEnvSet
25  
-}
26  
-
27  
-func runAppEnvSet(cmd *Command, args []string) {
28  
-	if len(args) < 3 {
29  
-		cmd.Flag.Usage()
30  
-	}
31  
-
32  
-	s := cmdAppEnvSet.Snapshot
33  
-	name := args[0]
34  
-	key := args[1]
35  
-	val := args[2]
36  
-
37  
-	app, err := visor.GetApp(s, name)
38  
-	if err != nil {
39  
-		fmt.Fprintf(os.Stderr, "Error fetching app %s\n", err.Error())
40  
-		os.Exit(1)
41  
-	}
42  
-
43  
-	_, err = app.SetEnvironmentVar(key, val)
44  
-	if err != nil {
45  
-		fmt.Fprintf(os.Stderr, "Error setting env var %s\n", err.Error())
46  
-		os.Exit(1)
47  
-	}
48  
-}
47  cmd/visor/app-head-set.go
... ...
@@ -1,47 +0,0 @@
1  
-// Copyright (c) 2012, SoundCloud Ltd.
2  
-// Use of this source code is governed by a BSD-style
3  
-// license that can be found in the LICENSE file.
4  
-// Source code and contact info at http://github.com/soundcloud/visor
5  
-
6  
-package main
7  
-
8  
-import (
9  
-	"fmt"
10  
-	"github.com/soundcloud/visor"
11  
-	"os"
12  
-)
13  
-
14  
-var cmdAppHeadSet = &Command{
15  
-	Name:      "app-head-set",
16  
-	Short:     "set the app head",
17  
-	UsageLine: "app-head-set <app> <head>",
18  
-	Long: `
19  
-App-head-set sets the latest revision of the app to <head>
20  
-  `,
21  
-}
22  
-
23  
-func init() {
24  
-	cmdAppHeadSet.Run = runAppHeadSet
25  
-}
26  
-
27  
-func runAppHeadSet(cmd *Command, args []string) {
28  
-	if len(args) < 2 {
29  
-		cmd.Flag.Usage()
30  
-	}
31  
-
32  
-	s := cmdAppHeadSet.Snapshot
33  
-	name := args[0]
34  
-	head := args[1]
35  
-
36  
-	app, err := visor.GetApp(s, name)
37  
-	if err != nil {
38  
-		fmt.Fprintf(os.Stderr, "Error fetching app %s\n", err.Error())
39  
-		os.Exit(1)
40  
-	}
41  
-
42  
-	_, err = app.SetHead(head)
43  
-	if err != nil {
44  
-		fmt.Fprintf(os.Stderr, "Error setting app head %s\n", err.Error())
45  
-		os.Exit(1)
46  
-	}
47  
-}
81  cmd/visor/app-instances-purge.go
... ...
@@ -1,81 +0,0 @@
1  
-// Copyright (c) 2012, SoundCloud Ltd.
2  
-// Use of this source code is governed by a BSD-style
3  
-// license that can be found in the LICENSE file.
4  
-// Source code and contact info at http://github.com/soundcloud/visor
5  
-
6  
-package main
7  
-
8  
-import (
9  
-	"fmt"
10  
-	"github.com/soundcloud/visor"
11  
-	"os"
12  
-)
13  
-
14  
-var cmdAppInstancesPurge = &Command{
15  
-	Name:      "app-instances-purge",
16  
-	Short:     "purge failed instances",
17  
-	UsageLine: "app-instances-purge <app> <rev> [proctype]",
18  
-	Long: `
19  
-App-instances-purge asks the coordinator to clean-up failed instances.
20  
-  `,
21  
-}
22  
-
23  
-func init() {
24  
-	cmdAppInstancesPurge.Run = runAppInstancesPurge
25  
-}
26  
-
27  
-func runAppInstancesPurge(cmd *Command, args []string) {
28  
-	if len(args) < 2 {
29  
-		cmd.Flag.Usage()
30  
-	}
31  
-	s := cmdAppInstancesPurge.Snapshot
32  
-
33  
-	appname := &args[0]
34  
-	revname := &args[1]
35  
-
36  
-	app, err := visor.GetApp(s, *appname)
37  
-	if err != nil {
38  
-		fmt.Fprintf(os.Stderr, "Error fetching app: %s\n", err.Error())
39  
-		os.Exit(1)
40  
-	}
41  
-
42  
-	switch len(args) {
43  
-	case 2:
44  
-		ptys, err := app.GetProcTypes()
45  
-		if err != nil {
46  
-			fmt.Fprintf(os.Stderr, "Error fetching proctypes: %s\n", err.Error())
47  
-			os.Exit(1)
48  
-		}
49  
-		for _, pty := range ptys {
50  
-			purgeProctypeInstances(pty, revname)
51  
-		}
52  
-	case 3:
53  
-		pty, err := visor.GetProcType(s, app, args[2])
54  
-		if err != nil {
55  
-			fmt.Fprintf(os.Stderr, "Error fetching proctype: %s\n", err.Error())
56  
-			os.Exit(1)
57  
-		}
58  
-		purgeProctypeInstances(pty, revname)
59  
-		return
60  
-	default:
61  
-		fmt.Fprintf(os.Stderr, "Wrong number of arguments")
62  
-		os.Exit(1)
63  
-	}
64  
-}
65  
-
66  
-func purgeProctypeInstances(pty *visor.ProcType, revname *string) {
67  
-	ins, err := pty.GetFailedInstances()
68  
-	if err != nil {
69  
-		fmt.Fprintf(os.Stderr, "Error fetching instances for %s: %s\n", pty.Name, err.Error())
70  
-		os.Exit(1)
71  
-	}
72  
-
73  
-	for _, i := range ins {
74  
-		if i.RevisionName == *revname {
75  
-			err := i.Unregister()
76  
-			if err != nil {
77  
-				fmt.Fprintf(os.Stderr, "Error removing instance %s: %s\n", i.Dir.Name, err.Error())
78  
-			}
79  
-		}
80  
-	}
81  
-}
70  cmd/visor/app-instances.go
... ...
@@ -1,70 +0,0 @@
1  
-// Copyright (c) 2012, SoundCloud Ltd.
2  
-// Use of this source code is governed by a BSD-style
3  
-// license that can be found in the LICENSE file.
4  
-// Source code and contact info at http://github.com/soundcloud/visor
5  
-
6  
-package main
7  
-
8  
-import (
9  
-	"fmt"
10  
-	"github.com/soundcloud/visor"
11  
-	"os"
12  
-)
13  
-
14  
-var cmdAppInstances = &Command{
15  
-	Name:      "app-instances",
16  
-	Short:     "list instances",
17  
-	UsageLine: "app-instances <name> [proc]",
18  
-	Long: `
19  
-App-instances returns instances and there state for an application.
20  
-  `,
21  
-}
22  
-
23  
-func init() {
24  
-	cmdAppInstances.Run = runAppInstances
25  
-}
26  
-
27  
-func runAppInstances(cmd *Command, args []string) {
28  
-	if len(args) < 1 {
29  
-		cmd.Flag.Usage()
30  
-	}
31  
-
32  
-	s := cmdAppInstances.Snapshot
33  
-
34  
-	app, err := visor.GetApp(s, args[0])
35  
-	if err != nil {
36  
-		fmt.Fprintf(os.Stderr, "Error fetching app %s\n", err.Error())
37  
-		os.Exit(1)
38  
-	}
39  
-
40  
-	ptys, err := app.GetProcTypes()
41  
-	if err != nil {
42  
-		fmt.Fprintf(os.Stderr, "Error fetching proctypes %s\n", err.Error())
43  
-		os.Exit(1)
44  
-	}
45  
-
46  
-	total := len(ptys)
47  
-	insch := make(chan []*visor.Instance, total)
48  
-
49  
-	for _, pty := range ptys {
50  
-		if len(args) >= 2 && string(pty.Name) != args[1] {
51  
-			total--
52  
-			continue
53  
-		}
54  
-		go func(pty *visor.ProcType) {
55  
-			ins, err := pty.GetInstances()
56  
-			if err != nil {
57  
-				fmt.Fprintf(os.Stderr, "Error fetching instances for %s %s\n", pty.Name, err)
58  
-				os.Exit(1)
59  
-			} else {
60  
-				insch <- ins
61  
-			}
62  
-		}(pty)
63  
-	}
64  
-
65  
-	for i := 0; i < total; i++ {
66  
-		for _, i := range <-insch {
67  
-			fmt.Fprintf(os.Stdout, "%s %s %s %s %s %s %d %s\n", i.Dir.Name, i.ServiceName(), i.AppName, i.ProcessName, i.RevisionName, i.Host, i.Port, i.Status)
68  
-		}
69  
-	}
70  
-}
39  cmd/visor/app-list.go
... ...
@@ -1,39 +0,0 @@
1  
-// Copyright (c) 2012, SoundCloud Ltd.
2  
-// Use of this source code is governed by a BSD-style
3  
-// license that can be found in the LICENSE file.
4  
-// Source code and contact info at http://github.com/soundcloud/visor
5  
-
6  
-package main
7  
-
8  
-import (
9  
-	"fmt"
10  
-	"github.com/soundcloud/visor"
11  
-	"os"
12  
-)
13  
-
14  
-var cmdAppList = &Command{
15  
-	Name:      "app-list",
16  
-	Short:     "lists apps",
17  
-	UsageLine: "app-list",
18  
-	Long: `
19  
-App-list returns all registered applications.
20  
-  `,
21  
-}
22  
-
23  
-func init() {
24  
-	cmdAppList.Run = runAppList
25  
-}
26  
-
27  
-func runAppList(cmd *Command, args []string) {
28  
-	s := cmdAppList.Snapshot
29  
-
30  
-	apps, err := visor.Apps(s)
31  
-	if err != nil {
32  
-		fmt.Fprintf(os.Stderr, "Error fetching apps %s\n", err.Error())
33  
-		os.Exit(1)
34  
-	}
35  
-
36  
-	for _, app := range apps {
37  
-		fmt.Fprintf(os.Stdout, "%s\n", app.Name)
38  
-	}
39  
-}
57  cmd/visor/app-register.go
... ...
@@ -1,57 +0,0 @@
1  
-// Copyright (c) 2012, SoundCloud Ltd.
2  
-// Use of this source code is governed by a BSD-style
3  
-// license that can be found in the LICENSE file.
4  
-// Source code and contact info at http://github.com/soundcloud/visor
5  
-
6  
-package main
7  
-
8  
-import (
9  
-	"fmt"
10  
-	"github.com/soundcloud/visor"
11  
-	"os"
12  
-)
13  
-
14  
-var cmdAppRegister = &Command{
15  
-	Name:      "app-register",
16  
-	Short:     "create app in global registry",
17  
-	UsageLine: "app-register [options] <name>",
18  
-	Long: `
19  
-App-register adds applications to the global registry.
20  
-
21  
-Options:
22  
-  -repo   CVS repository address (https://github.com/foo/<name>)
23  
-  -stack  Runtime stack to use (HEAD)
24  
-  -type   Application type (lxc)
25  
-  `,
26  
-}
27  
-
28  
-var r = cmdAppRegister.Flag.String("repo", "", "")
29  
-var s = cmdAppRegister.Flag.String("stack", "HEAD", "")
30  
-var t = cmdAppRegister.Flag.String("type", "lxc", "")
31  
-
32  
-func init() {
33  
-	cmdAppRegister.Run = runAppRegister
34  
-}
35  
-
36  
-func runAppRegister(cmd *Command, args []string) {
37  
-	if len(args) < 1 {
38  
-		cmd.Flag.Usage()
39  
-	}
40  
-
41  
-	name := args[0]
42  
-	repo := *r
43  
-	stack := *s
44  
-
45  
-	if len(repo) == 0 {
46  
-		repo = "https://github.com/foo/" + name
47  
-	}
48  
-
49  
-	app := visor.NewApp(name, repo, stack, cmdAppRegister.Snapshot)
50  
-	app.DeployType = *t
51  
-
52  
-	_, err := app.Register()
53  
-	if err != nil {
54  
-		fmt.Fprintf(os.Stderr, "Error registering app %s\n", err.Error())
55  
-		os.Exit(1)
56  
-	}
57  
-}
49  cmd/visor/app-revisions.go
... ...
@@ -1,49 +0,0 @@
1  
-// Copyright (c) 2012, SoundCloud Ltd.
2  
-// Use of this source code is governed by a BSD-style
3  
-// license that can be found in the LICENSE file.
4  
-// Source code and contact info at http://github.com/soundcloud/visor
5  
-
6  
-package main
7  
-
8  
-import (
9  
-	"fmt"
10  
-	"github.com/soundcloud/visor"
11  
-	"os"
12  
-)
13  
-
14  
-var cmdAppRevisions = &Command{
15  
-	Name:      "app-revisions",
16  
-	Short:     "list revisions for an app",
17  
-	UsageLine: "app-revisions <name>",
18  
-	Long: `
19  
-App-revisions returns revisions and meta information for an application.
20  
-  `,
21  
-}
22  
-
23  
-func init() {
24  
-	cmdAppRevisions.Run = runAppRevisions
25  
-}
26  
-
27  
-func runAppRevisions(cmd *Command, args []string) {
28  
-	if len(args) < 1 {
29  
-		cmd.Flag.Usage()
30  
-	}
31  
-
32  
-	s := cmdAppRevisions.Snapshot
33  
-
34  
-	app, err := visor.GetApp(s, args[0])
35  
-	if err != nil {
36  
-		fmt.Fprintf(os.Stderr, "Error fetching app %s\n", err.Error())
37  
-		os.Exit(1)
38  
-	}
39  
-
40  
-	revs, err := visor.AppRevisions(s, app)
41  
-	if err != nil {
42  
-		fmt.Fprintf(os.Stderr, "Error fetching revisions %s\n", err.Error())
43  
-		os.Exit(1)
44  
-	}
45  
-
46  
-	for _, rev := range revs {
47  
-		fmt.Fprintf(os.Stdout, "%s %s %s\n", rev.App.Name, rev.Ref, rev.ArchiveUrl)
48  
-	}
49  
-}
66  cmd/visor/app-services.go
... ...
@@ -1,66 +0,0 @@
1  
-// Copyright (c) 2012, SoundCloud Ltd.
2  
-// Use of this source code is governed by a BSD-style
3  
-// license that can be found in the LICENSE file.
4  
-// Source code and contact info at http://github.com/soundcloud/visor
5  
-
6  
-package main
7  
-
8  
-import (
9  
-	"fmt"
10  
-	"github.com/soundcloud/visor"
11  
-	"os"
12  
-)
13  
-
14  
-var cmdAppServices = &Command{
15  
-	Name:      "app-services",
16  
-	Short:     "list services for an app",
17  
-	UsageLine: "app-services <name>",
18  
-	Long: `
19  
-App-services returns services and meta information for an application.
20  
-  `,
21  
-}
22  
-
23  
-func init() {
24  
-	cmdAppServices.Run = runAppServices
25  
-}
26  
-
27  
-func runAppServices(cmd *Command, args []string) {
28  
-	if len(args) < 1 {
29  
-		cmd.Flag.Usage()
30  
-	}
31  
-
32  
-	s := cmdAppServices.Snapshot
33  
-
34  
-	app, err := visor.GetApp(s, args[0])
35  
-	if err != nil {
36  
-		fmt.Fprintf(os.Stderr, "Error fetching app %s\n", err.Error())
37  
-		os.Exit(1)
38  
-	}
39  
-
40  
-	proxies, err := s.GetProxies()
41  
-	if err != nil {
42  
-		fmt.Fprintf(os.Stderr, "Error fetching proxy addresses %s\n", err.Error())
43  
-		os.Exit(1)
44  
-	}
45  
-
46  
-	proxy := ""
47  
-	if len(proxies) > 0 {
48  
-		proxy = proxies[0]
49  
-	}
50  
-
51  
-	ptys, err := app.GetProcTypes()
52  
-	if err != nil {
53  
-		fmt.Fprintf(os.Stderr, "Error fetching proctypes %s\n", err.Error())
54  
-		os.Exit(1)
55  
-	}
56  
-
57  
-	for _, pty := range ptys {
58  
-		ins, err := pty.InstanceIds()
59  
-		if err != nil {
60  
-			fmt.Fprintf(os.Stderr, "Error fetching instances for %s %s\n", pty.Name, err.Error())
61  
-			os.Exit(1)
62  
-		}
63  
-
64  
-		fmt.Fprintf(os.Stdout, "%s-%s %s %d %d\n", pty.App.Name, pty.Name, proxy, pty.Port, len(ins))
65  
-	}
66  
-}
46  cmd/visor/app-unregister.go
... ...
@@ -1,46 +0,0 @@
1  
-// Copyright (c) 2012, SoundCloud Ltd.
2  
-// Use of this source code is governed by a BSD-style
3  
-// license that can be found in the LICENSE file.
4  
-// Source code and contact info at http://github.com/soundcloud/visor
5  
-
6  
-package main
7  
-
8  
-import (
9  
-	"fmt"
10  
-	"github.com/soundcloud/visor"
11  
-	"os"
12  
-)
13  
-
14  
-var cmdAppUnregister = &Command{
15  
-	Name:      "app-unregister",
16  
-	Short:     "remove app from the global registry",
17  
-	UsageLine: "app-unregister <name>",
18  
-	Long: `
19  
-App-unregister removes applications from the globa registry.
20  
-  `,
21  
-}
22  
-
23  
-func init() {
24  
-	cmdAppUnregister.Run = runAppUnregister
25  
-}
26  
-
27  
-func runAppUnregister(cmd *Command, args []string) {
28  
-	if len(args) < 1 {
29  
-		cmd.Flag.Usage()
30  
-	}
31  
-
32  
-	name := args[0]
33  
-	s := cmdAppUnregister.Snapshot
34  
-
35  
-	app, err := visor.GetApp(s, name)
36  
-	if err != nil {
37  
-		fmt.Fprintf(os.Stderr, "Error fetching app %s\n", err.Error())
38  
-		os.Exit(1)
39  
-	}
40  
-
41  
-	err = app.Unregister()
42  
-	if err != nil {
43  
-		fmt.Fprintf(os.Stderr, "Error unregistering app %s\n", err.Error())
44  
-		os.Exit(1)
45  
-	}
46  
-}
81  cmd/visor/endpoint-register.go
... ...
@@ -1,81 +0,0 @@
1  
-// Copyright (c) 2012, SoundCloud Ltd.
2  
-// Use of this source code is governed by a BSD-style
3  
-// license that can be found in the LICENSE file.
4  
-// Source code and contact info at http://github.com/soundcloud/visor
5  
-
6  
-package main
7  
-
8  
-import (
9  
-	"fmt"
10  
-	"github.com/soundcloud/visor"
11  
-	"os"
12  
-	"strconv"
13  
-)
14  
-
15  
-var cmdEndpointRegister = &Command{
16  
-	Name:      "endpoint-register",
17  
-	Short:     "create endpoint for service",
18  
-	UsageLine: "endpoint-register <service> <addr> <port> [priority] [weight]",
19  
-	Long: `
20  
-Endpoint-register adds an endpoint to a service in the global registry.
21  
-`,
22  
-}
23  
-
24  
-func init() {
25  
-	cmdEndpointRegister.Run = runEndpointRegister
26  
-}
27  
-
28  
-func runEndpointRegister(cmd *Command, args []string) {
29  
-	if len(args) < 3 {
30  
-		cmd.Flag.Usage()
31  
-	}
32  
-
33  
-	srv, err := visor.GetService(cmdEndpointRegister.Snapshot, args[0])
34  
-	if err != nil {
35  
-		fmt.Fprintf(os.Stderr, "Error fetching service %s\n", err.Error())
36  
-		os.Exit(1)
37  
-	}
38  
-
39  
-	if srv == nil {
40  
-		fmt.Fprint(os.Stderr, "service could not be found\n")
41  
-		os.Exit(1)
42  
-	}
43  
-
44  
-	port, err := strconv.ParseInt(args[2], 10, 0)
45  
-	if err != nil {
46  
-		fmt.Fprintf(os.Stderr, "port needs to be a positive integer %s\n", err.Error())
47  
-		os.Exit(1)
48  
-	}
49  
-
50  
-	ep, err := visor.NewEndpoint(srv, args[1], int(port), cmdEndpointRegister.Snapshot)
51  
-	if err != nil {
52  
-		fmt.Fprintf(os.Stderr, "Error %s\n", err.Error())
53  
-		os.Exit(1)
54  
-	}
55  
-
56  
-	if len(args) > 3 {
57  
-		prio, err := strconv.ParseInt(args[3], 10, 0)
58  
-		if err != nil {
59  
-			fmt.Fprintf(os.Stderr, "priority needs to be a positive integer %s\n", err.Error())
60  
-			os.Exit(1)
61  
-		}
62  
-
63  
-		ep.Priority = int(prio)
64  
-	}
65  
-
66  
-	if len(args) > 4 {
67  
-		weight, err := strconv.ParseInt(args[4], 10, 0)
68  
-		if err != nil {
69  
-			fmt.Fprintf(os.Stderr, "weight needs to be a positive integer %s\n", err.Error())
70  
-			os.Exit(1)
71  
-		}
72  
-
73  
-		ep.Weight = int(weight)
74  
-	}
75  
-
76  
-	_, err = ep.Register()
77  
-	if err != nil {
78  
-		fmt.Fprintf(os.Stderr, "Error registering endpoint %s\n", err.Error())
79  
-		os.Exit(1)
80  
-	}
81  
-}
62  cmd/visor/endpoint-unregister.go
... ...
@@ -1,62 +0,0 @@
1  
-// Copyright (c) 2012, SoundCloud Ltd.
2  
-// Use of this source code is governed by a BSD-style
3  
-// license that can be found in the LICENSE file.
4  
-// Source code and contact info at http://github.com/soundcloud/visor
5  
-
6  
-package main
7  
-
8  
-import (
9  
-	"fmt"
10  
-	"github.com/soundcloud/visor"
11  
-	"os"
12  
-	"strconv"
13  
-)
14  
-
15  
-var cmdEndpointUnregister = &Command{
16  
-	Name:      "endpoint-unregister",
17  
-	Short:     "remove endpoint for service",
18  
-	UsageLine: "endpoint-register <service> <addr> <port>",
19  
-	Long: `
20  
-Endpoint-unregister removes an endpoint for a service in the global registry.
21  
-`,
22  
-}
23  
-
24  
-func init() {
25  
-	cmdEndpointUnregister.Run = runEndpointUnregister
26  
-}
27  
-
28  
-func runEndpointUnregister(cmd *Command, args []string) {
29  
-	if len(args) < 3 {
30  
-		cmd.Flag.Usage()
31  
-	}
32  
-
33  
-	srv, err := visor.GetService(cmdEndpointUnregister.Snapshot, args[0])
34  
-	if err != nil {
35  
-		fmt.Fprintf(os.Stderr, "Error fetching service %s\n", err.Error())
36  
-		os.Exit(1)
37  
-	}
38  
-
39  
-	if srv == nil {
40  
-		fmt.Fprint(os.Stderr, "service could not be found\n")
41  
-		os.Exit(1)
42  
-	}
43  
-
44  
-	port, err := strconv.ParseInt(args[2], 10, 0)
45  
-	if err != nil {
46  
-		fmt.Fprintf(os.Stderr, "port needs to be a positive integer %s\n", err.Error())
47  
-		os.Exit(1)
48  
-	}
49  
-
50  
-	id := visor.EndpointId(args[1], int(port))
51  
-	ep, err := visor.GetEndpoint(cmdEndpointUnregister.Snapshot, srv, id)
52  
-	if err != nil {
53  
-		fmt.Fprintf(os.Stderr, "Error %s\n", err.Error())
54  
-		os.Exit(1)
55  
-	}
56  
-
57  
-	err = ep.Unregister()
58  
-	if err != nil {
59  
-		fmt.Fprintf(os.Stderr, "Error unregistering endpoint %s\n", err.Error())
60  
-		os.Exit(1)
61  
-	}
62  
-}
33  cmd/visor/init.go
... ...
@@ -1,33 +0,0 @@
1  
-// Copyright (c) 2012, SoundCloud Ltd.
2  
-// Use of this source code is governed by a BSD-style
3  
-// license that can be found in the LICENSE file.
4  
-// Source code and contact info at http://github.com/soundcloud/visor
5  
-
6  
-package main
7  
-
8  
-import (
9  
-	"fmt"
10  
-	"github.com/soundcloud/visor"
11  
-	"os"
12  
-)
13  
-
14  
-var cmdInit = &Command{
15  
-	Name:      "init",
16  
-	Short:     "initialize coordinator state",
17  
-	UsageLine: "scale",
18  
-	Long: `
19  
-Init takes care of basic setup of the coordinator tree structure.
20  
-  `,
21  
-}
22  
-
23  
-func init() {
24  
-	cmdInit.Run = runInit
25  
-}
26  
-
27  
-func runInit(cmd *Command, args []string) {
28  
-	_, err := visor.Init(cmdInit.Snapshot)
29  
-	if err != nil {
30  
-		fmt.Fprintf(os.Stderr, "Error initializing %s\n", err.Error())
31  
-		os.Exit(1)
32  
-	}
33  
-}
140  cmd/visor/main.go
... ...
@@ -1,140 +0,0 @@
1  
-// Copyright (c) 2012, SoundCloud Ltd.
2  
-// Use of this source code is governed by a BSD-style
3  
-// license that can be found in the LICENSE file.
4  
-// Source code and contact info at http://github.com/soundcloud/visor
5  
-
6  
-package main
7  
-
8  
-import (
9  
-	"flag"
10  
-	"fmt"
11  
-	"github.com/soundcloud/visor"
12  
-	"log"
13  
-	"os"
14  
-	"strings"
15  
-	"text/template"
16  
-)
17  
-
18  
-//
19  
-// Set *automatically* at link stage (see Makefile)
20  
-//
21  
-var VERSION string
22  
-
23  
-type Command struct {
24  
-	Run       func(cmd *Command, args []string)
25  
-	Flag      flag.FlagSet
26  
-	Long      string
27  
-	Name      string
28  
-	UsageLine string
29  
-	Short     string
30  
-	Snapshot  visor.Snapshot
31  
-}
32  
-
33  
-func (c *Command) Usage() {
34  
-	fmt.Fprintf(os.Stderr, "Usage: %s\n\n", c.UsageLine)
35  
-	fmt.Fprintf(os.Stderr, "%s\n", strings.TrimSpace(c.Long))
36  
-	os.Exit(1)
37  
-}
38  
-
39  
-var Uri string
40  
-var Root string
41  
-var Version bool
42  
-
43  
-func init() {
44  
-	flag.StringVar(&Uri, "uri", visor.DefaultUri, "doozer uri")
45  
-	flag.StringVar(&Root, "root", visor.DefaultRoot, "doozer root")
46  
-	flag.BoolVar(&Version, "version", false, "print version and exit")
47  
-}
48  
-
49  
-var commands = []*Command{
50  
-	cmdAppDescribe,
51  
-	cmdAppEnvDel,
52  
-	cmdAppEnvGet,
53  
-	cmdAppEnvSet,
54  
-	cmdAppHeadSet,
55  
-	cmdAppInstances,
56  
-	cmdAppInstancesPurge,
57  
-	cmdAppList,
58  
-	cmdAppRegister,
59  
-	cmdAppRevisions,
60  
-	cmdAppServices,
61  
-	cmdAppUnregister,
62  
-	cmdEndpointRegister,
63  
-	cmdEndpointUnregister,
64  
-	cmdInit,
65  
-	cmdProcRegister,
66  
-	cmdProcUnregister,
67  
-	cmdRevDescribe,
68  
-	cmdRevExists,
69  
-	cmdRevRegister,
70  
-	cmdRevUnregister,
71  
-	cmdScale,
72  
-	cmdServiceRegister,
73  
-	cmdServiceUnregister,
74  
-}
75  
-
76  
-func main() {
77  
-	flag.Usage = usage
78  
-	flag.Parse()
79  
-	log.SetFlags(0)
80  
-
81  
-	args := flag.Args()
82  
-
83  
-	if Version == true {
84  
-		fmt.Println(VERSION)
85  
-		os.Exit(0)
86  
-	}
87  
-
88  
-	if len(args) < 1 {
89  
-		usage()
90  
-	}
91  
-
92  
-	for _, cmd := range commands {
93  
-		if cmd.Name == args[0] && cmd.Run != nil {
94  
-			s, err := visor.DialUri(Uri, Root)
95  
-			if err != nil {
96  
-				fmt.Fprintf(os.Stderr, "Error connection %s\n", err.Error())
97  
-				os.Exit(1)
98  
-			}
99  
-
100  
-			cmd.Snapshot = s
101  
-			cmd.Flag.Usage = func() { cmd.Usage() }
102  
-			cmd.Flag.Parse(args[1:])
103  
-			cmd.Run(cmd, cmd.Flag.Args())
104  
-			return
105  
-		}
106  
-	}
107  
-
108  
-	fmt.Fprintf(os.Stderr, "Unknown command %#q\n\n", args[0])
109  
-	usage()
110  
-}
111  
-
112  
-func usage() {
113  
-	t := template.New("top")
114  
-	t.Funcs(template.FuncMap{"trim": strings.TrimSpace})
115  
-	template.Must(t.Parse(usageTmpl))
116  
-	data := struct {
117  
-		Commands []*Command
118  
-		Globals  map[string]string
119  
-	}{
120  
-		commands,
121  
-		map[string]string{"root": Root, "uri": Uri},
122  
-	}
123  
-
124  
-	if err := t.Execute(os.Stderr, data); err != nil {
125  
-		panic(err)
126  
-	}
127  
-
128  
-	os.Exit(1)
129  
-}
130  
-
131  
-var usageTmpl = `Usage: visor [globals] command [arguments]
132  
-
133  
-Globals:
134  
-  -root     Doozerd tree prefix ({{.Globals.root}})
135  
-  -uri      Doozerd cluster URI ({{.Globals.uri}})
136  
-  -version  Print version and exit
137  
-
138  
-Commands:{{range .Commands}}
139  
-  {{.Name | printf "%-20s"}} {{.Short}}{{end}}
140  
-`
48  cmd/visor/proc-register.go
... ...
@@ -1,48 +0,0 @@
1  
-// Copyright (c) 2012, SoundCloud Ltd.
2  
-// Use of this source code is governed by a BSD-style
3  
-// license that can be found in the LICENSE file.
4  
-// Source code and contact info at http://github.com/soundcloud/visor
5  
-
6  
-package main
7  
-
8  
-import (
9  
-	"fmt"
10  
-	"github.com/soundcloud/visor"
11  
-	"os"
12  
-)
13  
-
14  
-var cmdProcRegister = &Command{
15  
-	Name:      "proc-register",
16  
-	Short:     "create proctype",
17  
-	UsageLine: "proc-register <app> <name>",
18  
-	Long: `
19  
-Proc-register adds a new named proctype to an application.
20  
-  `,
21  
-}
22  
-
23  
-func init() {
24  
-	cmdProcRegister.Run = runProcRegister
25  
-}
26  
-
27  
-func runProcRegister(cmd *Command, args []string) {
28  
-	if len(args) < 2 {
29  
-		cmd.Flag.Usage()
30  
-	}
31  
-
32  
-	name := args[1]
33  
-	s := cmdProcRegister.Snapshot
34  
-
35  
-	app, err := visor.GetApp(s, args[0])
36  
-	if err != nil {
37  
-		fmt.Fprintf(os.Stderr, "Error fetching app %s\n", err.Error())
38  
-		os.Exit(1)
39  
-	}
40  
-
41  
-	proc := visor.NewProcType(app, name, s)
42  
-
43  
-	_, err = proc.Register()
44  
-	if err != nil {
45  
-		fmt.Fprintf(os.Stderr, "Error registering proc %s\n", err.Error())
46  
-		os.Exit(1)
47  
-	}
48  
-}
52  cmd/visor/proc-unregister.go
... ...
@@ -1,52 +0,0 @@
1  
-// Copyright (c) 2012, SoundCloud Ltd.
2  
-// Use of this source code is governed by a BSD-style
3  
-// license that can be found in the LICENSE file.
4  
-// Source code and contact info at http://github.com/soundcloud/visor
5  
-
6  
-package main
7  
-
8  
-import (
9  
-	"fmt"
10  
-	"github.com/soundcloud/visor"
11  
-	"os"
12  
-)
13  
-
14  
-var cmdProcUnregister = &Command{
15  
-	Name:      "proc-unregister",
16  
-	Short:     "remove proctype",
17  
-	UsageLine: "proc-unregister <app> <name>",
18  
-	Long: `
19  
-Proc-unregister removes a proctype from an application.
20  
-  `,
21  
-}
22  
-
23  
-func init() {
24  
-	cmdProcUnregister.Run = runProcUnregister
25  
-}
26  
-
27  
-func runProcUnregister(cmd *Command, args []string) {
28  
-	if len(args) < 2 {
29  
-		cmd.Flag.Usage()
30  
-	}
31  
-
32  
-	name := args[1]
33  
-	s := cmdProcUnregister.Snapshot
34  
-
35  
-	app, err := visor.GetApp(s, args[0])
36  
-	if err != nil {
37  
-		fmt.Fprintf(os.Stderr, "Error fetching app %s\n", err.Error())
38  
-		os.Exit(1)
39  
-	}
40  
-
41  
-	proc, err := visor.GetProcType(s, app, name)
42  
-	if err != nil {
43  
-		fmt.Fprintf(os.Stderr, "Error fetching proc %s\n", err.Error())
44  
-		os.Exit(1)
45  
-	}
46  
-
47  
-	err = proc.Unregister()