Skip to content

Commit

Permalink
Improve sysbox-mgr initizalization.
Browse files Browse the repository at this point in the history
Improve init by creating pid file after init process
completes. Thus the pid file can be used as an
indication that init completed successfully.

Signed-off-by: Cesar Talledo <cesar.talledo@docker.com>
  • Loading branch information
ctalledo committed Jul 19, 2022
1 parent 7877c5a commit e0419c4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
8 changes: 6 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ import (
"github.com/urfave/cli"
)

// Default subid range required by sysbox
var subidRangeSize uint64 = 65536
var (
sysboxRunDir string = "/run/sysbox"
sysboxLibDirDefault string = "/var/lib/sysbox"
sysboxMgrPidFile string = sysboxRunDir + "/sysmgr.pid"
subidRangeSize uint64 = 65536
)

const (
usage = `Sysbox manager daemon
Expand Down
25 changes: 11 additions & 14 deletions mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"fmt"
"os"
"path"
"path/filepath"
"sync"
"time"

Expand All @@ -41,11 +40,6 @@ import (
"github.com/urfave/cli"
)

const (
sysboxRunDir = "/run/sysbox"
sysboxLibDirDefault = "/var/lib/sysbox"
)

var sysboxLibDir string

type containerState int
Expand Down Expand Up @@ -134,6 +128,11 @@ type SysboxMgr struct {
func newSysboxMgr(ctx *cli.Context) (*SysboxMgr, error) {
var err error

err = libutils.CheckPidFile("sysbox-mgr", sysboxMgrPidFile)
if err != nil {
return nil, err
}

err = preFlightCheck()
if err != nil {
return nil, fmt.Errorf("preflight check failed: %s", err)
Expand All @@ -150,12 +149,6 @@ func newSysboxMgr(ctx *cli.Context) (*SysboxMgr, error) {
return nil, fmt.Errorf("failed to setup the sysbox run dir: %v", err)
}

pidFile := filepath.Join(sysboxRunDir, "sysmgr.pid")
err = libutils.CreatePidFile("sysbox-mgr", pidFile)
if err != nil {
return nil, fmt.Errorf("failed to create sysmgr.pid file: %s", err)
}

err = setupWorkDirs()
if err != nil {
return nil, fmt.Errorf("failed to setup the sysbox work dirs: %v", err)
Expand Down Expand Up @@ -329,6 +322,11 @@ func (mgr *SysboxMgr) Start() error {

systemd.SdNotify(false, systemd.SdNotifyReady)

err = libutils.CreatePidFile("sysbox-mgr", sysboxMgrPidFile)
if err != nil {
return fmt.Errorf("failed to create sysmgr.pid file: %s", err)
}

logrus.Info("Ready ...")

// listen for grpc connections
Expand Down Expand Up @@ -374,8 +372,7 @@ func (mgr *SysboxMgr) Stop() error {
logrus.Warnf("failed to cleanup work dirs: %v", err)
}

pidFile := filepath.Join(sysboxRunDir, "sysmgr.pid")
if err := libutils.DestroyPidFile(pidFile); err != nil {
if err := libutils.DestroyPidFile(sysboxMgrPidFile); err != nil {
logrus.Warnf("failed to destroy sysbox-mgr pid file: %v", err)
}

Expand Down

0 comments on commit e0419c4

Please sign in to comment.