mirror of
https://github.com/openfaas/faasd.git
synced 2025-06-21 14:23:34 +00:00
Upgrade to go-execute/v2
Upgrades to go-execute/v2 and updates various other dependencies. Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
@ -2,21 +2,23 @@ package systemd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"text/template"
|
||||
|
||||
execute "github.com/alexellis/go-execute/pkg/v1"
|
||||
execute "github.com/alexellis/go-execute/v2"
|
||||
)
|
||||
|
||||
func Enable(unit string) error {
|
||||
task := execute.ExecTask{Command: "systemctl",
|
||||
task := execute.ExecTask{
|
||||
Command: "systemctl",
|
||||
Args: []string{"enable", unit},
|
||||
StreamStdio: false,
|
||||
}
|
||||
|
||||
res, err := task.Execute()
|
||||
res, err := task.Execute(context.Background())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -29,12 +31,13 @@ func Enable(unit string) error {
|
||||
}
|
||||
|
||||
func Start(unit string) error {
|
||||
task := execute.ExecTask{Command: "systemctl",
|
||||
task := execute.ExecTask{
|
||||
Command: "systemctl",
|
||||
Args: []string{"start", unit},
|
||||
StreamStdio: false,
|
||||
}
|
||||
|
||||
res, err := task.Execute()
|
||||
res, err := task.Execute(context.Background())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -47,12 +50,13 @@ func Start(unit string) error {
|
||||
}
|
||||
|
||||
func DaemonReload() error {
|
||||
task := execute.ExecTask{Command: "systemctl",
|
||||
task := execute.ExecTask{
|
||||
Command: "systemctl",
|
||||
Args: []string{"daemon-reload"},
|
||||
StreamStdio: false,
|
||||
}
|
||||
|
||||
res, err := task.Execute()
|
||||
res, err := task.Execute(context.Background())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -71,23 +75,20 @@ func InstallUnit(name string, tokens map[string]string) error {
|
||||
|
||||
tmplName := "./hack/" + name + ".service"
|
||||
tmpl, err := template.ParseFiles(tmplName)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("error loading template %s, error %s", tmplName, err)
|
||||
}
|
||||
|
||||
var tpl bytes.Buffer
|
||||
|
||||
err = tmpl.Execute(&tpl, tokens)
|
||||
if err != nil {
|
||||
if err := tmpl.Execute(&tpl, tokens); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = writeUnit(name+".service", tpl.Bytes())
|
||||
|
||||
if err != nil {
|
||||
if err := writeUnit(name+".service", tpl.Bytes()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -96,7 +97,12 @@ func writeUnit(name string, data []byte) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer f.Close()
|
||||
_, err = f.Write(data)
|
||||
return err
|
||||
|
||||
if _, err := f.Write(data); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user