mirror of
https://github.com/openfaas/faasd.git
synced 2025-06-09 16:36:47 +00:00
Check for dependencies before installing
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
parent
0662605756
commit
5bb68e15f5
86
cmd/install.go
Normal file
86
cmd/install.go
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"path/filepath"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var installCmd = &cobra.Command{
|
||||||
|
Use: "install",
|
||||||
|
Short: "Install faasd",
|
||||||
|
RunE: runInstall,
|
||||||
|
}
|
||||||
|
|
||||||
|
func runInstall(_ *cobra.Command, _ []string) error {
|
||||||
|
|
||||||
|
err := binExists("/usr/local/bin/", "faas-containerd")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = binExists("/usr/local/bin/", "netns")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = installUnit("faas-containerd")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = installUnit("faasd")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func binExists(folder, name string) error {
|
||||||
|
findPath := path.Join(folder, name)
|
||||||
|
if _, err := os.Stat(findPath); err != nil {
|
||||||
|
return fmt.Errorf("unable to stat %s, install this binary before continuing", findPath)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func installUnit(name string) error {
|
||||||
|
|
||||||
|
tmpl, err := template.ParseFiles("./hack/" + name + ".service")
|
||||||
|
|
||||||
|
wd, _ := os.Getwd()
|
||||||
|
var tpl bytes.Buffer
|
||||||
|
userData := struct {
|
||||||
|
Cwd string
|
||||||
|
}{
|
||||||
|
Cwd: wd,
|
||||||
|
}
|
||||||
|
|
||||||
|
err = tmpl.Execute(&tpl, userData)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = writeUnit(name+".service", tpl.Bytes())
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeUnit(name string, data []byte) error {
|
||||||
|
f, err := os.Create(filepath.Join("/lib/systemd/system", name))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
_, err = f.Write(data)
|
||||||
|
return err
|
||||||
|
}
|
@ -22,6 +22,7 @@ const WelcomeMessage = "Welcome to faasd"
|
|||||||
func init() {
|
func init() {
|
||||||
rootCommand.AddCommand(versionCmd)
|
rootCommand.AddCommand(versionCmd)
|
||||||
rootCommand.AddCommand(upCmd)
|
rootCommand.AddCommand(upCmd)
|
||||||
|
rootCommand.AddCommand(installCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
var rootCommand = &cobra.Command{
|
var rootCommand = &cobra.Command{
|
||||||
|
12
hack/faas-containerd.service
Normal file
12
hack/faas-containerd.service
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=faasd-containerd
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
MemoryLimit=500M
|
||||||
|
ExecStart="/usr/local/bin/faas-containerd"
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=10s
|
||||||
|
WorkingDirectory="/usr/local/bin/"
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
13
hack/faasd.service
Normal file
13
hack/faasd.service
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=faasd
|
||||||
|
After=faas-containerd.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
MemoryLimit=500M
|
||||||
|
ExecStart={{.Cwd}}/faasd up
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=10s
|
||||||
|
WorkingDirectory={{.Cwd}}
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
Loading…
x
Reference in New Issue
Block a user