fix: systemd unit starts per-instance NGINX before Wallarm services
This commit is contained in:
parent
d8390eab2a
commit
b86d9d3604
1 changed files with 11 additions and 12 deletions
|
|
@ -223,38 +223,37 @@ func Status(nodeName string) (string, error) {
|
||||||
return sb.String(), nil
|
return sb.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenerateSystemdTemplate creates the wallarm-node@.service template unit if it doesn't exist.
|
// GenerateSystemdTemplate creates the wallarm-node@.service template unit.
|
||||||
func GenerateSystemdTemplate() error {
|
func GenerateSystemdTemplate() error {
|
||||||
if _, err := os.Stat(SystemdTemplate); err == nil {
|
if _, err := os.Stat(SystemdTemplate); err == nil {
|
||||||
return nil // already exists
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
content := fmt.Sprintf(`[Unit]
|
content := fmt.Sprintf(`[Unit]
|
||||||
Description=Wallarm Native Node - %%I
|
Description=Wallarm Node - %%i
|
||||||
After=network.target
|
After=network.target
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=forking
|
||||||
WorkingDirectory=%s/%%i
|
WorkingDirectory=%s/%%i
|
||||||
EnvironmentFile=%s/%%i/env
|
ExecStartPre=%s/%%i/nginx/sbin/nginx -c %s/%%i/nginx/conf/nginx.conf -t
|
||||||
ExecStart=%s/%%i/wallarm-native-node-aio.sh start
|
ExecStart=%s/%%i/nginx/sbin/nginx -c %s/%%i/nginx/conf/nginx.conf
|
||||||
ExecStop=%s/%%i/wallarm-native-node-aio.sh stop
|
ExecStartPost=/bin/bash %s/%%i/supervisord.sh start
|
||||||
|
ExecStop=/bin/bash %s/%%i/supervisord.sh stop
|
||||||
|
ExecStopPost=/bin/bash -c '%s/%%i/nginx/sbin/nginx -s quit 2>/dev/null || true'
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
RestartSec=5
|
RestartSec=5
|
||||||
User=root
|
User=root
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
`, NodesDir, NodesDir, NodesDir, NodesDir)
|
`, NodesDir, NodesDir, NodesDir, NodesDir, NodesDir, NodesDir, NodesDir, NodesDir)
|
||||||
|
|
||||||
if err := os.WriteFile(SystemdTemplate, []byte(content), 0644); err != nil {
|
if err := os.WriteFile(SystemdTemplate, []byte(content), 0644); err != nil {
|
||||||
return fmt.Errorf("write systemd template: %w", err)
|
return fmt.Errorf("write systemd template: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := exec.Command("systemctl", "daemon-reload")
|
exec.Command("systemctl", "daemon-reload").Run()
|
||||||
if out, err := cmd.CombinedOutput(); err != nil {
|
|
||||||
return fmt.Errorf("daemon-reload: %w\n%s", err, string(out))
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue