Skip to content

Commit

Permalink
add export
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmonsays committed Jan 19, 2016
1 parent 0fabb97 commit ad94097
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
41 changes: 41 additions & 0 deletions cmd/runitcmd/export.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

import (
"path/filepath"

"github.com/codegangsta/cli"
)

func initExport(app *Application) cli.Command {
description := "export service"
usage := "export service"

flags := []cli.Flag{}

cmd := cli.Command{
Name: "export",
Usage: usage,
Description: description,
Flags: flags,
Action: app.Export,
}
return cmd
}

func (app *Application) Export(c *cli.Context) {
for _, service := range app.MatchingServices(c) {

cfg, err := app.Runit.Export(service.Name)
if err != nil {
log.Warnf("export %s: %s", service.Name, err)
continue
}

destfile := filepath.Join("./", service.Name+".yaml")
err = cfg.SaveFile(destfile)
if err != nil {
log.Warnf("export %s: %s", service.Name, err)
continue
}
}
}
1 change: 1 addition & 0 deletions cmd/runitcmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func main() {
initCreate(app),
initApply(app),
initStatus(app),
initExport(app),

// more commands
makeCommand("delete", app.Delete),
Expand Down
10 changes: 10 additions & 0 deletions example/job1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: job1
exec: sleep 3600
disabled: false
activated: true
logging:
directory: /var/log/job1
size: 52428800
num: 10
timestamp: 2
redirect_stderr: true
24 changes: 24 additions & 0 deletions runit/export.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package runit

import (
"fmt"
"path/filepath"
)

func (runit *Runit) Export(name string) (*ServiceConfig, error) {
sv := runit.GetService(name)
if sv.Exists() == false {
return nil, fmt.Errorf("no such service")
}

configfile := filepath.Join(sv.ServiceDir, "service.yaml")

cfg := &ServiceConfig{}

err := cfg.LoadFile(configfile)
if err != nil {
return nil, err
}
return cfg, nil

}

0 comments on commit ad94097

Please sign in to comment.