Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.

Commit 9be3f82

Browse files
author
David Chung
authored
plugin start / catching panics / recover (#720)
Signed-off-by: David Chung <[email protected]>
1 parent 5a8272f commit 9be3f82

File tree

6 files changed

+38
-11
lines changed

6 files changed

+38
-11
lines changed

cmd/infrakit/plugin/plugin.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
139139
}
140140

141141
configURL := start.Flags().String("config-url", "", "URL for the startup configs")
142-
mustAll := start.Flags().Bool("all", true, "Panic if any plugin fails to start")
142+
mustAll := start.Flags().Bool("all", false, "Panic if any plugin fails to start")
143143
templateFlags, toJSON, _, processTemplate := base.TemplateProcessor(plugins)
144144
start.Flags().AddFlagSet(templateFlags)
145145

@@ -175,7 +175,15 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
175175
if err != nil {
176176
return err
177177
}
178-
defer pluginManager.Stop()
178+
defer func() {
179+
if r := recover(); r != nil {
180+
log.Error("Error occurred. Recovered but exiting.", "err", r)
181+
pluginManager.TerminateRunning()
182+
}
183+
pluginManager.WaitForAllShutdown()
184+
log.Info("All plugins shutdown")
185+
pluginManager.Stop()
186+
}()
179187

180188
if len(args) == 0 {
181189

@@ -228,9 +236,6 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
228236

229237
log.Info("Done waiting on plugin starts")
230238

231-
pluginManager.WaitForAllShutdown()
232-
log.Info("All plugins shutdown")
233-
234239
return nil
235240
}
236241

pkg/cli/v0/event/cmd.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ var log = logutil.New("module", "cli/v1/event")
1515
func init() {
1616
cli.Register(event.InterfaceSpec,
1717
[]cli.CmdBuilder{
18-
Event,
18+
Ls,
19+
Tail,
1920
})
2021
}
2122

pkg/cli/v0/event/ls.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414
func Ls(name string, services *cli.Services) *cobra.Command {
1515

1616
ls := &cobra.Command{
17-
Use: "ls",
18-
Short: "List event",
17+
Use: "topics",
18+
Short: "List event topics",
1919
}
2020

2121
long := ls.Flags().BoolP("long", "l", false, "Print full path")

pkg/cli/v0/metadata/cmd.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,24 @@ import (
1313
var log = logutil.New("module", "cli/v1/metadata")
1414

1515
func init() {
16+
// cli.Register(metadata.InterfaceSpec,
17+
// []cli.CmdBuilder{
18+
// Metadata,
19+
// })
20+
// cli.Register(metadata.UpdatableInterfaceSpec,
21+
// []cli.CmdBuilder{
22+
// Updatable,
23+
// })
1624
cli.Register(metadata.InterfaceSpec,
1725
[]cli.CmdBuilder{
18-
Metadata,
26+
Ls,
27+
Cat,
1928
})
2029
cli.Register(metadata.UpdatableInterfaceSpec,
2130
[]cli.CmdBuilder{
22-
Updatable,
31+
Ls,
32+
Cat,
33+
Change,
2334
})
2435
}
2536

pkg/cli/v0/metadata/ls.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
func Ls(name string, services *cli.Services) *cobra.Command {
1616

1717
ls := &cobra.Command{
18-
Use: "ls",
18+
Use: "vars",
1919
Short: "List metadata",
2020
}
2121

pkg/run/manager/manager.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func ManagePlugins(rules []launch.Rule,
3232
plugins: plugins,
3333
mustAll: mustAll,
3434
scanInterval: scanInterval,
35+
running: []string{},
3536
}
3637
return m, m.Start(rules)
3738
}
@@ -51,13 +52,20 @@ type Manager struct {
5152
wgStartAll sync.WaitGroup
5253
started chan plugin.Name
5354
lock sync.RWMutex
55+
56+
running []string // lookups of those started
5457
}
5558

5659
// Rules returns a list of plugins that can be launched via this manager
5760
func (m *Manager) Rules() []launch.Rule {
5861
return m.rules
5962
}
6063

64+
// TerminateRunning terminates those that have been started.
65+
func (m *Manager) TerminateRunning() error {
66+
return m.Terminate(m.running)
67+
}
68+
6169
// Terminate stops the plugins. Note this is accomplished by sending a signal TERM to the
6270
// process found at the lookup.pid file. For inproc plugins, this will effectively kill
6371
// all the plugins that run in that process.
@@ -228,6 +236,8 @@ func (m *Manager) WaitForAllShutdown() {
228236

229237
lookup, _ := target.GetLookupAndType()
230238

239+
m.running = append(m.running, lookup)
240+
231241
if _, has := seen[lookup]; !has {
232242
log.Debug("Start watching", "lookup", lookup)
233243
targets = append(targets, lookup)

0 commit comments

Comments
 (0)