more conf and add deployment commands
This commit is contained in:
parent
105f03bf67
commit
02b3ebf87b
4
Makefile
4
Makefile
|
@ -18,7 +18,9 @@ clean:
|
|||
install:
|
||||
cp cmd/warren/warren /usr/bin
|
||||
cp cmd/warrend/warrend /usr/bin
|
||||
mkdir /var/run/warrend
|
||||
mkdir -p /var/run/warrend
|
||||
cp -n cmd/warrend/etc/warrend.json /etc
|
||||
cp cmd/warrend/etc/init/warrend.conf /etc/init
|
||||
|
||||
uninstall:
|
||||
rm /usr/bin/warren
|
||||
|
|
|
@ -19,7 +19,7 @@ warren build - Runs go build and populates the following variables:
|
|||
|
||||
var buildCmd = &warren.Command{
|
||||
Name: "build",
|
||||
Usage: "",
|
||||
Usage: buildUsage,
|
||||
Summary: "build the go server in the current directory",
|
||||
Help: buildUsage,
|
||||
Run: buildRun,
|
||||
|
|
|
@ -13,7 +13,7 @@ warren deploy - Deploys the go server and support files
|
|||
|
||||
var deployCmd = &warren.Command{
|
||||
Name: "deploy",
|
||||
Usage: "",
|
||||
Usage: deployUsage,
|
||||
Summary: "deploy the go server and support files",
|
||||
Help: deployUsage,
|
||||
Run: deployRun,
|
||||
|
|
|
@ -17,7 +17,7 @@ warren run - Interfaces with warrend to manage running instances
|
|||
|
||||
var runCmd = &warren.Command{
|
||||
Name: "run",
|
||||
Usage: "",
|
||||
Usage: runUsage,
|
||||
Summary: "Interface to warrend to manage running instances",
|
||||
Help: runUsage,
|
||||
Run: runRun,
|
||||
|
|
|
@ -4,25 +4,18 @@ import (
|
|||
"fmt"
|
||||
"github.com/dballard/warren/lib/warren"
|
||||
"os"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
var BuildGitHash string
|
||||
var BuildGitBranch string
|
||||
var BuildDate string
|
||||
|
||||
var usagePrefix = `
|
||||
warren is a tool for building, deploying and running multiple versions of a Go server
|
||||
var usagePrefix = `warren is a tool for building, deploying and running multiple versions of a Go server
|
||||
|
||||
Usage:
|
||||
warren command [args]
|
||||
`
|
||||
|
||||
var usageTmpl = template.Must(template.New("usage").Parse(`
|
||||
Commands:{{range .}}
|
||||
{{.Name | printf "%-10s"}} {{.Summary}}{{end}}
|
||||
`))
|
||||
|
||||
func usage() {
|
||||
fmt.Println(BuildGitBranch, " ", BuildGitHash, " ", BuildDate)
|
||||
fmt.Print(usagePrefix)
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/dballard/warren/lib/warren"
|
||||
"net"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var regUsage = `
|
||||
status -
|
||||
`
|
||||
|
||||
var regCmd = &SockCommand{
|
||||
Command: warren.Command{
|
||||
Name: "reg",
|
||||
Usage: regUsage,
|
||||
Summary: "Register a deployment directory for running",
|
||||
Help: regUsage,
|
||||
},
|
||||
Run: regRun,
|
||||
}
|
||||
|
||||
// reg path [nickname]
|
||||
func regRun(cmd *SockCommand, c net.Conn, args ...string) {
|
||||
if (len(args) > 0 && args[0] == "help") || len(args) < 1 {
|
||||
warren.WriteStringz(c, cmd.Help)
|
||||
return
|
||||
}
|
||||
|
||||
// get either supplied nick or parse from dir
|
||||
d := new(Deployment)
|
||||
d.Path = args[0]
|
||||
if len(args) >= 2 && strings.TrimSpace(args[1]) != "" {
|
||||
d.Name = args[1]
|
||||
} else {
|
||||
parts := strings.Split(strings.Trim(d.Path, " /"), "/")
|
||||
if parts[len(parts)-1] == "deploy" {
|
||||
d.Name = parts[len(parts)-2]
|
||||
} else {
|
||||
d.Name = parts[len(parts)-1]
|
||||
}
|
||||
}
|
||||
err := addDeployment(d)
|
||||
if err != nil {
|
||||
warren.WriteStringz(c, "ERROR: "+err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
warren.WriteStringz(c, "Registered deployment "+d.Name+" at "+d.Path)
|
||||
}
|
|
@ -12,7 +12,7 @@ status -
|
|||
var statusCmd = &SockCommand{
|
||||
Command: warren.Command{
|
||||
Name: "status",
|
||||
Usage: "",
|
||||
Usage: statusUsage,
|
||||
Summary: "Print status of warrend",
|
||||
Help: statusUsage,
|
||||
},
|
||||
|
@ -25,5 +25,10 @@ func statusRun(cmd *SockCommand, c net.Conn, args ...string) {
|
|||
return
|
||||
}
|
||||
|
||||
warren.WriteStringz(c, "status")
|
||||
warren.WriteStringz(c, "Status\n")
|
||||
|
||||
for _, d := range deployments {
|
||||
warren.WriteStringz(c, d.Name+": "+d.Path)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/dballard/warren/lib/warren"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Conf struct {
|
||||
deployments []string
|
||||
}
|
||||
|
||||
var conf *Conf = nil
|
||||
|
||||
func LoadConf() {
|
||||
file, err := os.Open(warren.WarrendConf)
|
||||
if err != nil {
|
||||
fmt.Println("Error loading ", warren.WarrendConf, ": ", err)
|
||||
return
|
||||
}
|
||||
decoder := json.NewDecoder(file)
|
||||
conf = new(Conf)
|
||||
err = decoder.Decode(conf)
|
||||
if err != nil {
|
||||
conf = nil
|
||||
fmt.Println("Error parsing ", warren.WarrendConf, ": ", err)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Deployment struct {
|
||||
Name string
|
||||
Path string
|
||||
}
|
||||
|
||||
var deployments map[string]*Deployment = make(map[string]*Deployment)
|
||||
|
||||
func addDeployment(d *Deployment) error {
|
||||
// check if exists
|
||||
if _, ok := deployments[d.Name]; ok {
|
||||
return errors.New("Deployment with that name already exists")
|
||||
}
|
||||
|
||||
// check if dir exists
|
||||
if _, err := os.Stat(d.Path); err != nil {
|
||||
return err
|
||||
}
|
||||
// add to conf / save
|
||||
deployments[d.Name] = d
|
||||
|
||||
// TODO: register with runner, like conf would
|
||||
|
||||
return nil
|
||||
}
|
|
@ -22,6 +22,10 @@ func (cmd *SockCommand) GetName() string {
|
|||
return cmd.Name
|
||||
}
|
||||
|
||||
func (cmd *SockCommand) GetSummary() string {
|
||||
return cmd.Summary
|
||||
}
|
||||
|
||||
func (cmd *SockCommand) Exec(c net.Conn, args []string) {
|
||||
cmd.Flag.Usage = func() {
|
||||
// helpFunc(c, c.Name)
|
||||
|
@ -82,7 +86,7 @@ func initRunning() {
|
|||
// drop down pid
|
||||
pidfile, err := os.Create(warren.WarrendPidFile)
|
||||
if err != nil {
|
||||
log.Fatal("Could not create pidfile: ", warren.WarrendPidFile(), " : ", err)
|
||||
log.Fatal("Could not create pidfile: ", warren.WarrendPidFile, " : ", err)
|
||||
}
|
||||
pid := os.Getpid()
|
||||
fmt.Fprintf(pidfile, "%d", pid)
|
||||
|
@ -109,9 +113,15 @@ func main() {
|
|||
log.Fatal("warrend instance already running")
|
||||
}
|
||||
|
||||
LoadConf()
|
||||
if conf == nil {
|
||||
log.Fatal("failed to load conf")
|
||||
}
|
||||
|
||||
initRunning()
|
||||
|
||||
warren.RegisterCommand(statusCmd)
|
||||
warren.RegisterCommand(regCmd)
|
||||
|
||||
// Handle signals
|
||||
c := make(chan os.Signal, 1)
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
type ICommand interface {
|
||||
GetName() string
|
||||
GetSummary() string
|
||||
}
|
||||
|
||||
var commands map[string]ICommand = make(map[string]ICommand)
|
||||
|
@ -30,6 +31,10 @@ func (c *Command) GetName() string {
|
|||
return c.Name
|
||||
}
|
||||
|
||||
func (c *Command) GetSummary() string {
|
||||
return c.Summary
|
||||
}
|
||||
|
||||
func (c *Command) Exec(args []string) {
|
||||
c.Flag.Usage = func() {
|
||||
// helpFunc(c, c.Name)
|
||||
|
@ -47,8 +52,8 @@ func GetCommand(name string) ICommand {
|
|||
}
|
||||
|
||||
var usageTmpl = template.Must(template.New("usage").Parse(`
|
||||
Commands:{{range .}}
|
||||
{{.Name | printf "%-10s"}} {{.Summary}}{{end}}
|
||||
Commands:{{range $k, $v := .}}
|
||||
{{$v.GetName| printf "%-10s"}} {{$v.GetSummary}}{{end}}
|
||||
`))
|
||||
|
||||
func PrintCommandUsage() {
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
const CmdSockType string = "unix"
|
||||
const CmdSockAddr string = "/var/run/warrend/warrend.sock"
|
||||
const WarrendPidFile string = "/var/run/warrend/warrend.pid"
|
||||
const WarrendConf string = "/etc/warrend.conf"
|
||||
const WarrendConf string = "/etc/warrend.json"
|
||||
|
||||
func GitHash() string {
|
||||
hash, err := exec.Command("git", "rev-parse", "HEAD").Output()
|
||||
|
|
Loading…
Reference in New Issue