[WIP] Add restart command to instance
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user