Skip to content

Commit 13c54c8

Browse files
committed
resmgr: write a PID file upon successful startup.
1 parent e002a8b commit 13c54c8

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

pkg/cri/resource-manager/flags.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"time"
2020

2121
"github.com/intel/cri-resource-manager/pkg/cri/resource-manager/sockets"
22+
"github.com/intel/cri-resource-manager/pkg/pidfile"
2223
)
2324

2425
// Options captures our command line parameters.
@@ -29,6 +30,7 @@ type options struct {
2930
RelayDir string
3031
AgentSocket string
3132
ConfigSocket string
33+
PidFile string
3234
ResctrlPath string
3335
FallbackConfig string
3436
ForceConfig string
@@ -58,7 +60,8 @@ func init() {
5860
"local socket of the cri-resmgr agent to connect")
5961
flag.StringVar(&opt.ConfigSocket, "config-socket", sockets.ResourceManagerConfig,
6062
"Unix domain socket path where the resource manager listens for cri-resmgr-agent")
61-
63+
flag.StringVar(&opt.PidFile, "pid-file", pidfile.GetPath(),
64+
"PID file to write daemon PID to")
6265
flag.StringVar(&opt.FallbackConfig, "fallback-config", "",
6366
"Fallback configuration to use unless/until one is available from the cache or agent.")
6467
flag.StringVar(&opt.ForceConfig, "force-config", "",

pkg/cri/resource-manager/resource-manager.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"github.com/intel/cri-resource-manager/pkg/cri/resource-manager/visualizer"
3737
"github.com/intel/cri-resource-manager/pkg/instrumentation"
3838
logger "github.com/intel/cri-resource-manager/pkg/log"
39+
"github.com/intel/cri-resource-manager/pkg/pidfile"
3940

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

120121
if err := m.setupRelay(); err != nil {
122+
pid, _ := pidfile.Read()
123+
if pid > 0 {
124+
m.Error("looks like we're already running as pid %d...", pid)
125+
}
121126
return nil, err
122127
}
123128

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

173+
if err := pidfile.Remove(); err != nil {
174+
return resmgrError("failed to remove stale/old PID file: %v", err)
175+
}
176+
if err := pidfile.Write(); err != nil {
177+
return resmgrError("failed to write PID file: %v", err)
178+
}
179+
168180
if opt.ForceConfig == "" {
169181
if err := m.configServer.Start(opt.ConfigSocket); err != nil {
170182
return resmgrError("failed to start configuration server: %v", err)

0 commit comments

Comments
 (0)