-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move initialization code from init() to main(), see #32
- Loading branch information
1 parent
55ef6f0
commit 023b5df
Showing
6 changed files
with
74 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// initialize internal objects | ||
// we keep this separated from main.go to minimize the amount of modification to generated code. | ||
|
||
package main | ||
|
||
import ( | ||
"os" | ||
"time" | ||
|
||
internal "github.com/kraken-hpc/imageapi/internal/api" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
const collectTime = time.Second * 1 | ||
|
||
func initInternal() { | ||
internal.Log = logrus.New() | ||
// fixme: read from os.Env? | ||
logLevel := logrus.InfoLevel | ||
if val, ok := os.LookupEnv("IMAGEAPI_LOGLEVEL"); ok { | ||
if ll, ok := internal.LogStringToLL[val]; ok { | ||
logLevel = ll | ||
} | ||
} | ||
internal.MountDir = "/var/run/imageapi/mounts" | ||
internal.LogDir = "/var/run/imageapi/logs" | ||
if val, ok := os.LookupEnv("IMAGEAPI_MOUNTDIR"); ok { | ||
internal.MountDir = val | ||
} | ||
if val, ok := os.LookupEnv("IMAGEAPI_LOGDIR"); ok { | ||
internal.LogDir = val | ||
} | ||
|
||
internal.ForkInit() | ||
|
||
internal.Log.Level = logLevel | ||
internal.Log.Info("initializing imageapi-server") | ||
internal.Rbds = &internal.RbdsType{} | ||
internal.Rbds.Init() | ||
internal.MountsRbd = &internal.MountsRBDType{} | ||
internal.MountsRbd.Init() | ||
internal.MountsOverlay = &internal.MountsOverlayType{} | ||
internal.MountsOverlay.Init() | ||
internal.Containers = &internal.ContainersType{} | ||
internal.Containers.Init() | ||
internal.Log.WithField("collectTime", collectTime).Debug("starting garbage collection") | ||
|
||
go func() { | ||
for { | ||
time.Sleep(collectTime) | ||
internal.GarbageCollect() | ||
} | ||
}() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters