Set wd to /run/faasd

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
Alex Ellis (OpenFaaS Ltd)
2020-01-05 09:05:21 +00:00
committed by Alex Ellis
parent fd4f53fe15
commit 3068d03279
3 changed files with 26 additions and 6 deletions

View File

@ -23,6 +23,11 @@ func runInstall(_ *cobra.Command, _ []string) error {
return errors.Wrap(basicAuthErr, "cannot create basic-auth-* files")
}
wd := "/run/faasd"
if err := ensureWorkingDir(wd); err != nil {
return err
}
err := binExists("/usr/local/bin/", "faas-containerd")
if err != nil {
return err
@ -38,12 +43,12 @@ func runInstall(_ *cobra.Command, _ []string) error {
return err
}
err = systemd.InstallUnit("faas-containerd")
err = systemd.InstallUnit("faas-containerd", wd)
if err != nil {
return err
}
err = systemd.InstallUnit("faasd")
err = systemd.InstallUnit("faasd", wd)
if err != nil {
return err
}
@ -83,3 +88,14 @@ func binExists(folder, name string) error {
}
return nil
}
func ensureWorkingDir(folder string) error {
if _, err := os.Stat(folder); err != nil {
err = os.MkdirAll("/run/faasd", 0600)
if err != nil {
return err
}
}
return nil
}

View File

@ -7,7 +7,7 @@ MemoryLimit=500M
ExecStart=/usr/local/bin/faas-containerd
Restart=on-failure
RestartSec=10s
WorkingDirectory=/usr/local/bin/
WorkingDirectory={{.Cwd}}
[Install]
WantedBy=multi-user.target

View File

@ -64,7 +64,12 @@ func DaemonReload() error {
return nil
}
func InstallUnit(name string) error {
func InstallUnit(name, folder string) error {
if len(folder) == 0 {
wd, _ := os.Getwd()
folder = wd
}
tmplName := "./hack/" + name + ".service"
tmpl, err := template.ParseFiles(tmplName)
@ -72,12 +77,11 @@ func InstallUnit(name string) error {
return fmt.Errorf("error loading template %s, error %s", tmplName, err)
}
wd, _ := os.Getwd()
var tpl bytes.Buffer
userData := struct {
Cwd string
}{
Cwd: wd,
Cwd: folder,
}
err = tmpl.Execute(&tpl, userData)