working great on MacOS

This commit is contained in:
AJ ONeal 2019-07-02 00:25:16 -06:00
parent 20d460c70e
commit 8527c632f8
6 changed files with 34 additions and 19 deletions

View File

@ -64,8 +64,8 @@
{{ end -}}
<key>StandardErrorPath</key>
<string>{{ .LogDir }}/{{ .Name }}.log</string>
<string>{{ .Logdir }}/{{ .Name }}.log</string>
<key>StandardOutPath</key>
<string>{{ .LogDir }}/{{ .Name }}.log</string>
<string>{{ .Logdir }}/{{ .Name }}.log</string>
</dict>
</plist>

View File

@ -65,7 +65,7 @@ type Config struct {
Group string `json:"group"`
home string `json:"-"`
Local string `json:"-"`
LogDir string `json:"-"`
Logdir string `json:"-"`
System bool `json:"system"`
Restart bool `json:"restart"`
Production bool `json:"production"`
@ -96,7 +96,7 @@ func Install(c *Config) error {
return err
}
err = os.MkdirAll(c.LogDir, 0750)
err = os.MkdirAll(c.Logdir, 0755)
if nil != err {
return err
}

View File

@ -25,7 +25,7 @@ func install(c *Config) error {
}
// Check paths first
err := os.MkdirAll(filepath.Dir(plistDir), 0750)
err := os.MkdirAll(filepath.Dir(plistDir), 0755)
if nil != err {
return err
}
@ -52,13 +52,19 @@ func install(c *Config) error {
plistName := c.ReverseDNS + ".plist"
plistPath := filepath.Join(plistDir, plistName)
if err := ioutil.WriteFile(plistPath, rw.Bytes(), 0644); err != nil {
fmt.Println("Use 'sudo' to install as a privileged system service.")
fmt.Println("Use '--userspace' to install as an user service.")
return fmt.Errorf("ioutil.WriteFile error: %v", err)
}
fmt.Printf("Installed. To start '%s' run the following:\n", c.Name)
// TODO template config file
fmt.Printf("\tlaunchctl load -w %s\n", strings.Replace(plistPath, c.home, "~", 1))
if "" != c.home {
plistPath = strings.Replace(plistPath, c.home, "~", 1)
}
sudo := ""
if c.System {
sudo = "sudo "
}
fmt.Printf("\t%slaunchctl load -w %s\n", sudo, plistPath)
return nil
}

View File

@ -31,10 +31,10 @@ func install(c *Config) error {
// * ~/.config/systemd/user/watchdog.service
// https://wiki.archlinux.org/index.php/Systemd/User
serviceDir = filepath.Join(c.home, ".local/share/systemd/user")
}
err := os.MkdirAll(filepath.Dir(serviceDir), 0750)
if nil != err {
return err
err := os.MkdirAll(filepath.Dir(serviceDir), 0755)
if nil != err {
return err
}
}
// Create service file from template

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,6 @@ package main
import (
"flag"
"fmt"
"log"
"os"
"path/filepath"
"strings"
@ -114,9 +113,9 @@ func main() {
return
}
conf.Local = filepath.Join(home, ".local")
conf.LogDir = filepath.Join(home, ".local", "share", conf.Name, "var", "log")
conf.Logdir = filepath.Join(home, ".local", "share", conf.Name, "var", "log")
} else {
conf.LogDir = "/var/log/" + conf.Name
conf.Logdir = "/var/log/" + conf.Name
}
// Check to see if Exec exists
@ -149,12 +148,22 @@ func main() {
}
fmt.Fprintf(os.Stderr, "Using '%s' anyway.\n", conf.Exec)
}
} else {
execpath, err := filepath.Abs(conf.Exec)
if nil != err {
fmt.Fprintf(os.Stderr, "Unrecoverable Error: %s", err)
os.Exit(4)
} else {
conf.Exec = execpath
}
}
fmt.Printf("\n%#v\n\n", conf)
err = installer.Install(conf)
if nil != err {
log.Fatal(err)
fmt.Fprintf(os.Stderr, "%s\n", err)
fmt.Fprintf(os.Stderr, "Use 'sudo' to install as a privileged system service.\n")
fmt.Fprintf(os.Stderr, "Use '--user' to install as an user service.\n")
}
}