Browse files

misc, webserver: use circus to manage git-daemon

  • Loading branch information...
1 parent 86ffabc commit 53e1dba67a98db39ba56ac80ad597d1bb792b945 @fsouza fsouza committed Jan 21, 2013
Showing with 6 additions and 79 deletions.
  1. +6 −0 misc/circus.ini
  2. +0 −15 webserver/main.go
  3. +0 −64 webserver/main_test.go
View
6 misc/circus.ini
@@ -10,6 +10,12 @@ cmd = /home/git/gandalf/dist/gandalf-webserver
uid = git
copy_env = True
+[watcher:git-daemon]
+cmd = git
+args = daemon --base-path=/repositories/path --syslog --export-all
+copy_env = True
+uid = git
+
[watcher:mongodb]
cmd = /home/ubuntu/tsuru/start-mongo.bash
args = /var/lib/mongodb
View
15 webserver/main.go
@@ -6,28 +6,14 @@ package main
import (
"flag"
- "fmt"
"github.com/bmizerany/pat"
"github.com/globocom/config"
"github.com/globocom/gandalf/api"
"github.com/globocom/gandalf/db"
"log"
"net/http"
- "os/exec"
)
-func startGitDaemon() error {
- bLocation, err := config.GetString("git:bare:location")
- if err != nil {
- return err
- }
- args := []string{"daemon", fmt.Sprintf("--base-path=%s", bLocation), "--syslog"}
- if exportAll, err := config.GetBool("git:daemon:export-all"); err == nil && exportAll {
- args = append(args, "--export-all")
- }
- return exec.Command("git", args...).Run()
-}
-
func main() {
dry := flag.Bool("dry", false, "dry-run: does not start the server and git daemon (for testing purpose)")
configFile := flag.String("config", "/etc/gandalf.conf", "Gandalf configuration file")
@@ -55,7 +41,6 @@ For an example conf check gandalf/etc/gandalf.conf file.`
panic(err)
}
if !*dry {
- startGitDaemon()
log.Fatal(http.ListenAndServe(port, router))
}
}
View
64 webserver/main_test.go
@@ -1,64 +0,0 @@
-// Copyright 2013 gandalf authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package main
-
-import (
- "fmt"
- "github.com/globocom/commandmocker"
- "github.com/globocom/config"
- . "launchpad.net/gocheck"
- "testing"
-)
-
-func Test(t *testing.T) { TestingT(t) }
-
-type S struct {
- tmpdir string
-}
-
-var _ = Suite(&S{})
-
-func (s *S) SetUpSuite(c *C) {
- err := config.ReadConfigFile("../etc/gandalf.conf")
- c.Assert(err, IsNil)
-}
-
-func (s *S) SetUpTest(c *C) {
- var err error
- s.tmpdir, err = commandmocker.Add("git", "$*")
- c.Assert(err, IsNil)
-}
-
-func (s *S) TearDownTest(c *C) {
- commandmocker.Remove(s.tmpdir)
-}
-
-func (s *S) TestStartGitDaemonShouldCallGitDaemonCmd(c *C) {
- err := startGitDaemon()
- c.Assert(err, IsNil)
- c.Assert(commandmocker.Ran(s.tmpdir), Equals, true)
- barePath, err := config.GetString("git:bare:location")
- c.Assert(err, IsNil)
- expected := fmt.Sprintf("daemon --base-path=%s --syslog.*", barePath)
- c.Assert(commandmocker.Output(s.tmpdir), Matches, expected)
-}
-
-func (s *S) TestStartGitDaemonShouldRepassExportAllConfig(c *C) {
- err := startGitDaemon()
- c.Assert(err, IsNil)
- c.Assert(commandmocker.Ran(s.tmpdir), Equals, true)
- expected := ".* --export-all.*"
- c.Assert(commandmocker.Output(s.tmpdir), Matches, expected)
-}
-
-func (s *S) TestStartGitDaemonShouldNotRepassExportAllWhenItsSetToFalse(c *C) {
- config.Set("git:daemon:export-all", false)
- defer config.Set("git:daemon:export-all", true)
- err := startGitDaemon()
- c.Assert(err, IsNil)
- c.Assert(commandmocker.Ran(s.tmpdir), Equals, true)
- expected := ".* --export-all.*"
- c.Assert(commandmocker.Output(s.tmpdir), Not(Matches), expected)
-}

0 comments on commit 53e1dba

Please sign in to comment.