Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
(SDI-2199) Fix #1344 binary change to snaptel/snapteld
Browse files Browse the repository at this point in the history
  • Loading branch information
nanliu committed Nov 21, 2016
1 parent b5483d4 commit d1c48a8
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 43 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ plugins:
all:
bash -c "./scripts/build_all.sh"
install:
cp build/$(OS)/$(ARCH)/snapd /usr/local/bin/
cp build/$(OS)/$(ARCH)/snapctl /usr/local/bin/
cp build/$(OS)/$(ARCH)/snapteld /usr/local/sbin/
cp build/$(OS)/$(ARCH)/snaptel /usr/local/bin/
proto:
cd `echo $(GOPATH) | cut -d: -f 1`; bash -c "./src/github.com/intelsdi-x/snap/scripts/gen-proto.sh"
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion cmd/snapctl/main.go → cmd/snaptel/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func newUsageError(s string, ctx *cli.Context) usageError {

func main() {
app := cli.NewApp()
app.Name = "snapctl"
app.Name = "snaptel"
app.Version = gitversion
app.Usage = "The open telemetry framework"
app.Flags = []cli.Flag{flURL, flSecure, flAPIVer, flPassword, flConfig}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions scripts/build_snap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ else
fi

mkdir -p "${build_path}"
_info "building snapd/snapctl for ${GOOS}/${GOARCH}"
"${go_build[@]}" -o "${build_path}/snapd" . || exit 1
(cd "${__proj_dir}/cmd/snapctl" && "${go_build[@]}" -o "${build_path}/snapctl" . || exit 1)
_info "building snapteld/snaptel for ${GOOS}/${GOARCH}"
"${go_build[@]}" -o "${build_path}/snapteld" . || exit 1
(cd "${__proj_dir}/cmd/snaptel" && "${go_build[@]}" -o "${build_path}/snaptel" . || exit 1)
75 changes: 38 additions & 37 deletions snapd.go → snapteld.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const (
defaultLogPath string = ""
defaultLogTruncate bool = false
defaultLogColors bool = true
defaultConfigPath string = "/etc/snap/snapd.conf"
defaultConfigPath string = "/etc/snap/snapteld.conf"
)

// holds the configuration passed in through the SNAP config file
Expand All @@ -131,17 +131,17 @@ type Config struct {
const (
CONFIG_CONSTRAINTS = `{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "snapd global config schema",
"title": "snapteld global config schema",
"type": ["object", "null"],
"properties": {
"log_level": {
"description": "log verbosity level for snapd. Range between 1: debug, 2: info, 3: warning, 4: error, 5: fatal",
"description": "log verbosity level for snapteld. Range between 1: debug, 2: info, 3: warning, 4: error, 5: fatal",
"type": "integer",
"minimum": 1,
"maximum": 5
},
"log_path": {
"description": "path to log file for snapd to use",
"description": "path to log file for snapteld to use",
"type": "string"
},
"log_truncate": {
Expand Down Expand Up @@ -170,6 +170,7 @@ const (
tribe.CONFIG_CONSTRAINTS +
`}` +
`}`
logModule = "snapteld"
)

type coreModule interface {
Expand All @@ -196,7 +197,7 @@ func main() {
}

cliApp = cli.NewApp()
cliApp.Name = "snapd"
cliApp.Name = "snapteld"
cliApp.Version = gitversion
cliApp.Usage = "The open telemetry framework"
cliApp.Flags = []cli.Flag{
Expand Down Expand Up @@ -259,7 +260,7 @@ func action(ctx *cli.Context) error {
if cfg.LogTruncate {
aMode = os.O_TRUNC
}
file, err := os.OpenFile(fmt.Sprintf("%s/snapd.log", logPath), os.O_RDWR|os.O_CREATE|aMode, 0666)
file, err := os.OpenFile(fmt.Sprintf("%s/snapteld.log", logPath), os.O_RDWR|os.O_CREATE|aMode, 0666)
if err != nil {
log.Fatal(err)
}
Expand All @@ -273,23 +274,23 @@ func action(ctx *cli.Context) error {
//
// We could also restrict this command line parameter to only apply when no logpath is given
// and forcing the coloring to off when using a file but this might not please users who like to use
// redirect mechanisms like # snapd -t 0 -l 1 2>&1 | tee my.log
// redirect mechanisms like # snapteld -t 0 -l 1 2>&1 | tee my.log
if !cfg.LogColors {
log.SetFormatter(&log.TextFormatter{FullTimestamp: true, DisableColors: true})
} else {
log.SetFormatter(&log.TextFormatter{FullTimestamp: true})
}

// Validate log level and trust level settings for snapd
// Validate log level and trust level settings for snapteld
validateLevelSettings(cfg.LogLevel, cfg.Control.PluginTrust)

// Switch log level to user defined
log.SetLevel(getLevel(cfg.LogLevel))
log.Info("setting log level to: ", l[cfg.LogLevel])

log.Info("Starting snapd (version: ", gitversion, ")")
log.Info("Starting snapteld (version: ", gitversion, ")")

// Set Max Processors for snapd.
// Set Max Processors for snapteld.
setMaxProcs(cfg.GoMaxProcs)

c := control.New(cfg.Control)
Expand Down Expand Up @@ -389,7 +390,7 @@ func action(ctx *cli.Context) error {
log.WithFields(
log.Fields{
"block": "main",
"_module": "snapd",
"_module": logModule,
}).Fatal("need keyring file when trust is on (--keyring-file or -k)")
}
for _, k := range keyrings {
Expand All @@ -398,7 +399,7 @@ func action(ctx *cli.Context) error {
log.WithFields(
log.Fields{
"block": "main",
"_module": "snapd",
"_module": logModule,
"error": err.Error(),
"keyringPath": keyringPath,
}).Fatal("Unable to determine absolute path to keyring file")
Expand All @@ -408,7 +409,7 @@ func action(ctx *cli.Context) error {
log.WithFields(
log.Fields{
"block": "main",
"_module": "snapd",
"_module": logModule,
"error": err.Error(),
"keyringPath": keyringPath,
}).Fatal("bad keyring file")
Expand All @@ -420,7 +421,7 @@ func action(ctx *cli.Context) error {
log.WithFields(
log.Fields{
"_block": "main",
"_module": "snapd",
"_module": logModule,
"error": err.Error(),
"keyringPath": keyringPath,
}).Fatal(err)
Expand All @@ -438,7 +439,7 @@ func action(ctx *cli.Context) error {
log.WithFields(
log.Fields{
"block": "main",
"_module": "snapd",
"_module": logModule,
"error": err.Error(),
"keyringPath": keyringPath,
}).Warning("unable to open keyring file. not adding to keyring path")
Expand All @@ -455,7 +456,7 @@ func action(ctx *cli.Context) error {
log.WithFields(
log.Fields{
"block": "main",
"_module": "snapd",
"_module": logModule,
"error": err.Error(),
"keyringPath": keyringPath,
}).Fatal("unable to open keyring file.")
Expand All @@ -470,8 +471,8 @@ func action(ctx *cli.Context) error {
log.WithFields(
log.Fields{
"block": "main",
"_module": "snapd",
}).Info("snapd started", `
"_module": logModule,
}).Info("snapteld started", `
ss ss
odyssyhhyo oyhysshhoyo
ddddyssyyysssssyyyyyyyssssyyysssyhy+-
Expand Down Expand Up @@ -510,7 +511,7 @@ func action(ctx *cli.Context) error {
select {} //run forever and ever
}

// get the default snapd configuration
// get the default snapteld configuration
func getDefaultConfig() *Config {
return &Config{
LogLevel: defaultLogLevel,
Expand All @@ -525,7 +526,7 @@ func getDefaultConfig() *Config {
}
}

// Read the snapd configuration from a configuration file
// Read the snapteld configuration from a configuration file
func readConfig(cfg *Config, fpath string) {
var path string
if !defaultConfigFile() && fpath == "" {
Expand Down Expand Up @@ -780,7 +781,7 @@ func applyCmdLineFlags(cfg *Config, ctx *cli.Context) {
}
invertBoolean := true
// apply any command line flags that might have been set, first for the
// snapd-related flags
// snapteld-related flags
cfg.GoMaxProcs = setIntVal(cfg.GoMaxProcs, ctx, "max-procs")
cfg.LogLevel = setIntVal(cfg.LogLevel, ctx, "log-level")
cfg.LogPath = setStringVal(cfg.LogPath, ctx, "log-path")
Expand Down Expand Up @@ -850,9 +851,9 @@ func monitorErrors(ch <-chan error) {
log.Fatal(err)
}

// setMaxProcs configures runtime.GOMAXPROCS for snapd. GOMAXPROCS can be set by using
// the env variable GOMAXPROCS and snapd will honor this setting. A user can override the env
// variable by setting max-procs flag on the command line. Snapd will be limited to the max CPUs
// setMaxProcs configures runtime.GOMAXPROCS for snapteld. GOMAXPROCS can be set by using
// the env variable GOMAXPROCS and snapteld will honor this setting. A user can override the env
// variable by setting max-procs flag on the command line. snapteld will be limited to the max CPUs
// on the system even if the env variable or the command line setting is set above the max CPUs.
// The default value if the env variable or the command line option is not set is 1.
func setMaxProcs(maxProcs int) {
Expand All @@ -863,14 +864,14 @@ func setMaxProcs(maxProcs int) {
log.WithFields(
log.Fields{
"_block": "main",
"_module": "snapd",
"_module": logModule,
"maxprocs": maxProcs,
}).Error("Trying to set GOMAXPROCS to an invalid value")
_maxProcs = 1
log.WithFields(
log.Fields{
"_block": "main",
"_module": "snapd",
"_module": logModule,
"maxprocs": _maxProcs,
}).Warning("Setting GOMAXPROCS to 1")
_maxProcs = 1
Expand All @@ -880,14 +881,14 @@ func setMaxProcs(maxProcs int) {
log.WithFields(
log.Fields{
"_block": "main",
"_module": "snapd",
"_module": logModule,
"maxprocs": maxProcs,
}).Error("Trying to set GOMAXPROCS larger than number of CPUs available on system")
_maxProcs = numProcs
log.WithFields(
log.Fields{
"_block": "main",
"_module": "snapd",
"_module": logModule,
"maxprocs": _maxProcs,
}).Warning("Setting GOMAXPROCS to number of CPUs on host")
}
Expand All @@ -900,7 +901,7 @@ func setMaxProcs(maxProcs int) {
log.WithFields(
log.Fields{
"block": "main",
"_module": "snapd",
"_module": logModule,
"given maxprocs": _maxProcs,
"real maxprocs": actualNumProcs,
}).Warning("not using given maxprocs")
Expand Down Expand Up @@ -970,7 +971,7 @@ func startModule(m coreModule) error {
log.WithFields(
log.Fields{
"block": "main",
"_module": "snapd",
"_module": logModule,
"snap-module": m.Name(),
}).Info("module started")
}
Expand All @@ -981,7 +982,7 @@ func printErrorAndExit(name string, err error) {
log.WithFields(
log.Fields{
"block": "main",
"_module": "snapd",
"_module": logModule,
"error": err.Error(),
"snap-module": name,
}).Fatal("error starting module")
Expand All @@ -997,14 +998,14 @@ func startInterruptHandling(modules ...coreModule) {
log.WithFields(
log.Fields{
"block": "main",
"_module": "snapd",
"_module": logModule,
}).Info("shutting down modules")

for _, m := range modules {
log.WithFields(
log.Fields{
"block": "main",
"_module": "snapd",
"_module": logModule,
"snap-module": m.Name(),
}).Info("stopping module")
m.Stop()
Expand All @@ -1014,7 +1015,7 @@ func startInterruptHandling(modules ...coreModule) {
log.WithFields(
log.Fields{
"block": "main",
"_module": "snapd",
"_module": logModule,
"signal": sig.String(),
}).Info("restarting app")
// and restart the app (with the current configuration)
Expand All @@ -1026,7 +1027,7 @@ func startInterruptHandling(modules ...coreModule) {
log.WithFields(
log.Fields{
"block": "main",
"_module": "snapd",
"_module": logModule,
"signal": sig.String(),
}).Info("exiting on signal")
os.Exit(0)
Expand Down Expand Up @@ -1056,15 +1057,15 @@ func validateLevelSettings(logLevel, pluginTrust int) {
log.WithFields(
log.Fields{
"block": "main",
"_module": "snapd",
"_module": logModule,
"level": logLevel,
}).Fatal("log level was invalid (needs: 1-5)")
}
if pluginTrust < 0 || pluginTrust > 2 {
log.WithFields(
log.Fields{
"block": "main",
"_module": "snapd",
"_module": logModule,
"level": pluginTrust,
}).Fatal("Plugin trust was invalid (needs: 0-2)")
}
Expand Down

0 comments on commit d1c48a8

Please sign in to comment.