WIP tested linux system installer
This commit is contained in:
parent
fb4f0c5a69
commit
c9b6fd62a0
|
@ -1,16 +1,15 @@
|
||||||
# Pre-req
|
# Pre-req
|
||||||
# sudo mkdir -p {{ .Local }}/opt/{{ .Name }}/ {{ .Local }}/var/log/{{ .Name }}
|
# sudo mkdir -p {{ .Local }}/opt/{{ .Name }}/ {{ .Local }}/var/log/{{ .Name }}
|
||||||
{{ if not .Local -}}
|
{{ if not .Local -}}
|
||||||
{{ if .User -}}
|
{{- if and .User ( ne "root" .User ) -}}
|
||||||
# sudo adduser {{ .User }} --home /opt/{{ .Name }}
|
# sudo adduser {{ .User }} --home /opt/{{ .Name }}
|
||||||
# sudo chown -R {{ .User }}:{{ .Group }} /opt/{{ .Name }}/ /var/log/{{ .Name }}
|
# sudo chown -R {{ .User }}:{{ .Group }} /opt/{{ .Name }}/ /var/log/{{ .Name }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{ end -}}
|
||||||
|
|
||||||
# Post-install
|
# Post-install
|
||||||
# sudo systemctl {{ if .Local -}} --user {{- end }} daemon-reload
|
# sudo systemctl {{ if .Local -}} --user {{ end -}} daemon-reload
|
||||||
# sudo systemctl {{ if .Local -}} --user {{- end }} restart {{ .Name }}.service
|
# sudo systemctl {{ if .Local -}} --user {{ end -}} restart {{ .Name }}.service
|
||||||
# sudo journalctl {{ if .Local -}} --user {{- end }} -xefu {{ .Name }}
|
# sudo journalctl {{ if .Local -}} --user {{ end -}} -xefu {{ .Name }}
|
||||||
|
|
||||||
[Unit]
|
[Unit]
|
||||||
Description={{ .Title }} - {{ .Desc }}
|
Description={{ .Title }} - {{ .Desc }}
|
||||||
|
|
|
@ -32,7 +32,7 @@ func install(c *Config) error {
|
||||||
// https://wiki.archlinux.org/index.php/Systemd/User
|
// https://wiki.archlinux.org/index.php/Systemd/User
|
||||||
serviceDir = filepath.Join(c.home, ".local/share/systemd/user")
|
serviceDir = filepath.Join(c.home, ".local/share/systemd/user")
|
||||||
}
|
}
|
||||||
err = os.MkdirAll(filepath.Dir(serviceDir), 0750)
|
err := os.MkdirAll(filepath.Dir(serviceDir), 0750)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,18 @@ func install(c *Config) error {
|
||||||
if err := ioutil.WriteFile(servicePath, rw.Bytes(), 0644); err != nil {
|
if err := ioutil.WriteFile(servicePath, rw.Bytes(), 0644); err != nil {
|
||||||
return fmt.Errorf("ioutil.WriteFile error: %v", err)
|
return fmt.Errorf("ioutil.WriteFile error: %v", err)
|
||||||
}
|
}
|
||||||
fmt.Printf("Wrote %q\n", servicePath)
|
|
||||||
|
|
||||||
|
// TODO template this as well?
|
||||||
|
userspace := ""
|
||||||
|
sudo := "sudo "
|
||||||
|
if !c.System {
|
||||||
|
userspace = "--user "
|
||||||
|
sudo = ""
|
||||||
|
}
|
||||||
|
fmt.Printf("System service installed as '%s'.\n", servicePath)
|
||||||
|
fmt.Printf("Run the following to start '%s':\n", c.Name)
|
||||||
|
fmt.Printf("\t" + sudo + "systemctl " + userspace + "daemon-reload\n")
|
||||||
|
fmt.Printf("\t"+sudo+"systemctl "+userspace+"restart %s.service\n", c.Name)
|
||||||
|
fmt.Printf("\t"+sudo+"journalctl "+userspace+"-xefu %s\n", c.Name)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue