[WIP] Add restart command to instance

This commit is contained in:
Vladimir Stoilov
2024-09-26 13:51:42 +03:00
parent c9631daa3e
commit 61babe2822
15 changed files with 81 additions and 98 deletions

View File

@@ -4,14 +4,19 @@ import (
"fmt"
"log/slog"
"os"
"os/exec"
"os/signal"
"syscall"
"time"
processInfo "github.com/shirou/gopsutil/process"
"github.com/safing/portmaster/base/log"
"github.com/safing/portmaster/service"
)
var defaultRestartCommand = exec.Command("systemctl", "restart", "portmaster")
func run(instance *service.Instance) {
// Set default log level.
log.SetLogLevel(log.WarningLevel)
@@ -98,3 +103,20 @@ func run(instance *service.Instance) {
os.Exit(instance.ExitCode())
}
func isRunningAsService() bool {
// Get the current process ID
pid := os.Getpid()
currentProcess, err := processInfo.NewProcess(int32(pid))
if err != nil {
return false
}
ppid, err := currentProcess.Ppid()
if err != nil {
return false
}
// Check if the parent process ID is 1 == init system
return ppid == 1
}