windows fixes, mkdir fixes, json cleanup

This commit is contained in:
AJ ONeal 2019-07-03 00:43:59 -06:00
parent 9ca2168113
commit 196fdee7ac
3 changed files with 29 additions and 18 deletions

View File

@ -108,7 +108,7 @@ func installServiceman(c *service.Service) ([]string, error) {
// TODO support service level services (which probably wouldn't need serviceman) // TODO support service level services (which probably wouldn't need serviceman)
smdir = filepath.Join(c.Home, ".local", smdir) smdir = filepath.Join(c.Home, ".local", smdir)
// for now we'll scope the runner to the name of the application // for now we'll scope the runner to the name of the application
smbin := filepath.Join(smdir, `bin\serviceman.%s`, c.Name) smbin := filepath.Join(smdir, `bin\serviceman.`+c.Name)
if smbin != self { if smbin != self {
err := os.MkdirAll(filepath.Dir(smbin), 0755) err := os.MkdirAll(filepath.Dir(smbin), 0755)
@ -130,8 +130,13 @@ func installServiceman(c *service.Service) ([]string, error) {
// this should be impossible, so we'll just panic // this should be impossible, so we'll just panic
panic(err) panic(err)
} }
confpath := filepath.Join(smdir, `etc`, c.Name+`.json`) confpath := filepath.Join(smdir, `etc`)
err = ioutil.WriteFile(confpath, b, 0640) err = os.MkdirAll(confpath, 0755)
if nil != err {
return nil, err
}
conffile := filepath.Join(confpath, c.Name+`.json`)
err = ioutil.WriteFile(conffile, b, 0640)
if nil != err { if nil != err {
return nil, err return nil, err
} }
@ -140,7 +145,7 @@ func installServiceman(c *service.Service) ([]string, error) {
smbin, smbin,
"run", "run",
"--config", "--config",
confpath, conffile,
}, nil }, nil
} }

View File

@ -49,26 +49,26 @@ import (
// These are documented as omitted from JSON. // These are documented as omitted from JSON.
// Try to stick to what's outlined above. // Try to stick to what's outlined above.
type Service struct { type Service struct {
Title string `json:"title"` Title string `json:"title,omitempty"`
Name string `json:"name"` Name string `json:"name"`
Desc string `json:"desc"` Desc string `json:"desc,omitempty"`
URL string `json:"url"` URL string `json:"url,omitempty"`
ReverseDNS string `json:"reverse_dns"` // i.e. com.example.foo-app ReverseDNS string `json:"reverse_dns"` // i.e. com.example.foo-app
Interpreter string `json:"interpreter"` // i.e. node, python Interpreter string `json:"interpreter,omitempty"` // i.e. node, python
Exec string `json:"exec"` Exec string `json:"exec"`
Argv []string `json:"argv"` Argv []string `json:"argv,omitempty"`
Workdir string `json:"workdir"` Workdir string `json:"workdir,omitempty"`
Envs map[string]string `json:"envs"` Envs map[string]string `json:"envs,omitempty"`
User string `json:"user"` User string `json:"user,omitempty"`
Group string `json:"group"` Group string `json:"group,omitempty"`
Home string `json:"-"` Home string `json:"-"`
Local string `json:"-"` Local string `json:"-"`
Logdir string `json:"logdir"` Logdir string `json:"logdir"`
System bool `json:"system"` System bool `json:"system"`
Restart bool `json:"restart"` Restart bool `json:"restart"`
Production bool `json:"production"` Production bool `json:"production,omitempty"`
PrivilegedPorts bool `json:"privileged_ports"` PrivilegedPorts bool `json:"privileged_ports,omitempty"`
MultiuserProtection bool `json:"multiuser_protection"` MultiuserProtection bool `json:"multiuser_protection,omitempty"`
} }
func (s *Service) Normalize(force bool) { func (s *Service) Normalize(force bool) {

View File

@ -123,7 +123,7 @@ func install() {
conf.Normalize(force) conf.Normalize(force)
fmt.Printf("\n%#v\n\n", conf) //fmt.Printf("\n%#v\n\n", conf)
err = installer.Install(conf) err = installer.Install(conf)
if nil != err { if nil != err {
@ -179,6 +179,12 @@ func run() {
s.Normalize(false) s.Normalize(false)
fmt.Fprintf(os.Stdout, "Logdir: %s\n", s.Logdir) fmt.Fprintf(os.Stdout, "Logdir: %s\n", s.Logdir)
err = os.MkdirAll(s.Logdir, 0755)
if nil != err {
fmt.Fprintf(os.Stderr, "%s\n", err)
return
}
if !daemonize { if !daemonize {
fmt.Fprintf(os.Stdout, "Running %s %s %s\n", s.Interpreter, s.Exec, strings.Join(s.Argv, " ")) fmt.Fprintf(os.Stdout, "Running %s %s %s\n", s.Interpreter, s.Exec, strings.Join(s.Argv, " "))
runner.Run(s) runner.Run(s)