Skip to content

Commit

Permalink
resmgr: write a PID file upon successful startup.
Browse files Browse the repository at this point in the history
  • Loading branch information
klihub committed Jan 5, 2022
1 parent ff10e9f commit 06b9f08
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/cri/resource-manager/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"time"

"github.com/intel/cri-resource-manager/pkg/cri/resource-manager/sockets"
"github.com/intel/cri-resource-manager/pkg/pidfile"
)

// Options captures our command line parameters.
Expand All @@ -29,6 +30,7 @@ type options struct {
RelayDir string
AgentSocket string
ConfigSocket string
PidFile string
ResctrlPath string
FallbackConfig string
ForceConfig string
Expand Down Expand Up @@ -58,7 +60,8 @@ func init() {
"local socket of the cri-resmgr agent to connect")
flag.StringVar(&opt.ConfigSocket, "config-socket", sockets.ResourceManagerConfig,
"Unix domain socket path where the resource manager listens for cri-resmgr-agent")

flag.StringVar(&opt.PidFile, "pid-file", pidfile.GetPath(),
"PID file to write daemon PID to")
flag.StringVar(&opt.FallbackConfig, "fallback-config", "",
"Fallback configuration to use unless/until one is available from the cache or agent.")
flag.StringVar(&opt.ForceConfig, "force-config", "",
Expand Down
12 changes: 12 additions & 0 deletions pkg/cri/resource-manager/resource-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/intel/cri-resource-manager/pkg/cri/resource-manager/visualizer"
"github.com/intel/cri-resource-manager/pkg/instrumentation"
logger "github.com/intel/cri-resource-manager/pkg/log"
"github.com/intel/cri-resource-manager/pkg/pidfile"

policyCollector "github.com/intel/cri-resource-manager/pkg/policycollector"
"github.com/intel/cri-resource-manager/pkg/utils"
Expand Down Expand Up @@ -118,6 +119,10 @@ func NewResourceManager() (ResourceManager, error) {
}

if err := m.setupRelay(); err != nil {
pid, _ := pidfile.OwnerPid()
if pid > 0 {
m.Error("looks like we're already running as pid %d...", pid)
}
return nil, err
}

Expand Down Expand Up @@ -165,6 +170,13 @@ func (m *resmgr) Start() error {
return resmgrError("failed to start CRI relay: %v", err)
}

if err := pidfile.Remove(); err != nil {
return resmgrError("failed to remove stale/old PID file: %v", err)
}
if err := pidfile.Write(); err != nil {
return resmgrError("failed to write PID file: %v", err)
}

if opt.ForceConfig == "" {
if err := m.configServer.Start(opt.ConfigSocket); err != nil {
return resmgrError("failed to start configuration server: %v", err)
Expand Down

0 comments on commit 06b9f08

Please sign in to comment.