fix: proper systemd template, auto-enable after deploy
This commit is contained in:
parent
bf3ba41179
commit
ddf0dd9884
1 changed files with 46 additions and 5 deletions
|
|
@ -106,7 +106,13 @@ func InstallNode(node state.Node, apiToken, apiHost, labels string) error {
|
|||
os.MkdirAll(filepath.Join(BaseDir, node.Name), 0755)
|
||||
os.RemoveAll(instanceDir)
|
||||
os.Rename(DeployTo, instanceDir)
|
||||
fmt.Printf("[%s] Done. Installed to %s\n", node.Name, instanceDir)
|
||||
|
||||
// 9. Set up systemd service
|
||||
GenerateSystemdTemplate()
|
||||
svc := "wallarm-node@" + node.Name
|
||||
exec.Command("systemctl", "enable", svc).Run()
|
||||
exec.Command("systemctl", "start", svc).Run()
|
||||
fmt.Printf("[%s] Done. Installed to %s (systemctl status %s)\n", node.Name, instanceDir, svc)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -141,10 +147,45 @@ func cloudFromHost(host string) string {
|
|||
return "EU"
|
||||
}
|
||||
|
||||
func CreateNodesDir() error { return os.MkdirAll(BaseDir, 0755) }
|
||||
func GenerateSystemdTemplate() error { return nil }
|
||||
func RemoveNode(name string) error { return nil }
|
||||
func Status(name string) (string, error) { return "", nil }
|
||||
func CreateNodesDir() error { return os.MkdirAll(BaseDir, 0755) }
|
||||
|
||||
func GenerateSystemdTemplate() error {
|
||||
tmpl := `/etc/systemd/system/wallarm-node@.service`
|
||||
if _, err := os.Stat(tmpl); err == nil {
|
||||
return nil // already exists
|
||||
}
|
||||
content := fmt.Sprintf(`[Unit]
|
||||
Description=Wallarm Node - %%i
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=forking
|
||||
WorkingDirectory=%s/%%i/wallarm
|
||||
ExecStart=/bin/bash %s/%%i/wallarm/supervisord.sh start
|
||||
ExecStop=/bin/bash %s/%%i/wallarm/supervisord.sh stop
|
||||
Restart=on-failure
|
||||
RestartSec=5
|
||||
User=root
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
`, BaseDir, BaseDir, BaseDir)
|
||||
os.WriteFile(tmpl, []byte(content), 0644)
|
||||
exec.Command("systemctl", "daemon-reload").Run()
|
||||
return nil
|
||||
}
|
||||
|
||||
func RemoveNode(name string) error {
|
||||
exec.Command("systemctl", "stop", "wallarm-node@"+name).Run()
|
||||
exec.Command("systemctl", "disable", "wallarm-node@"+name).Run()
|
||||
os.RemoveAll(filepath.Join(BaseDir, name))
|
||||
return nil
|
||||
}
|
||||
|
||||
func Status(name string) (string, error) {
|
||||
out, _ := exec.Command("systemctl", "status", "wallarm-node@"+name, "--no-pager").CombinedOutput()
|
||||
return string(out), nil
|
||||
}
|
||||
|
||||
func startNginx(dir string, node state.Node, port string) {
|
||||
nginxDir := filepath.Join(dir, "nginx")
|
||||
|
|
|
|||
Loading…
Reference in a new issue