in integration/example/service/daemon.go [124:185]
func (d *Daemon) daemonHandler(ctx context.Context, cancel context.CancelFunc) error {
if d.configFilePath == "" {
d.configFilePath = LinuxConfigPath
}
if d.lp.OSType == "windows" {
d.configFilePath = WindowsConfigPath
}
log.Logger.Infof("Reading configuration from %s", d.configFilePath)
c, err := common.Read(d.configFilePath, os.ReadFile, &epb.Configuration{})
if err != nil {
return err
}
log.Logger.Info("Configuration read successfully")
d.config = c.(*epb.Configuration)
d.applyConfigurationDefaults()
d.lp.LogToCloud = d.config.GetLogToCloud().GetValue()
d.lp.Level = common.LogLevelToZapcore(d.config.GetLogLevel().Number())
if d.config.GetCloudProperties().GetProjectId() != "" {
d.lp.CloudLoggingClient = log.CloudLoggingClient(ctx, d.config.GetCloudProperties().GetProjectId())
}
if d.lp.CloudLoggingClient != nil {
defer d.lp.CloudLoggingClient.Close()
}
// setup logging with the configuration read from the config file.
log.SetupLogging(d.lp)
log.Logger.Infow("Agent version currently running", "version", d.Integration.GetAgentVersion())
log.Logger.Infow("Cloud Properties from metadata server",
"projectid", d.cloudProps.GetProjectId(),
"projectnumber", d.cloudProps.GetNumericProjectId(),
"instanceid", d.cloudProps.GetInstanceId(),
"zone", d.cloudProps.GetZone(),
"instancename", d.cloudProps.GetInstanceName(),
"image", d.cloudProps.GetImage())
d.configureUsageMetricsForDaemon(d.cloudProps)
usagemetrics.Started()
log.Logger.Info("Daemon started")
shutdownch := make(chan os.Signal, 1)
signal.Notify(shutdownch, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
// Start the services for the integration.
d.services = []Service{
&Fast{config: d.config},
&Slow{config: d.config},
}
for _, service := range d.services {
log.Logger.Infof("Daemon starting service: %s", service.String())
recoverableStart := &recovery.RecoverableRoutine{
Routine: service.Start,
ErrorCode: service.ErrorCode(),
ExpectedMinDuration: service.ExpectedMinDuration(),
UsageLogger: *usagemetrics.UsageLogger,
}
recoverableStart.StartRoutine(ctx)
}
// Log a RUNNING usage metric once a day.
go usagemetrics.LogRunningDaily()
// Wait for the shutdown signal.
d.waitForShutdown(ctx, shutdownch, cancel)
return nil
}