Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(344)

Side by Side Diff: client/cmd/logdog_butler/main.go

Issue 2114253002: LogDog Butler: Catch SIGTERM on Linux. (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | client/cmd/logdog_butler/main_posix.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package main 5 package main
6 6
7 import ( 7 import (
8 "errors" 8 "errors"
9 "flag" 9 "flag"
10 "fmt" 10 "fmt"
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 if err != nil { 252 if err != nil {
253 log.WithError(err).Errorf(a, "Failed to generate user pr efix.") 253 log.WithError(err).Errorf(a, "Failed to generate user pr efix.")
254 return configErrorReturnCode 254 return configErrorReturnCode
255 } 255 }
256 a.prefix = prefix 256 a.prefix = prefix
257 } 257 }
258 258
259 // Signal handler to catch 'Control-C'. This will gracefully shutdown th e 259 // Signal handler to catch 'Control-C'. This will gracefully shutdown th e
260 // butler the first time a signal is received. It will die abruptly if t he 260 // butler the first time a signal is received. It will die abruptly if t he
261 // signal continues to be received. 261 // signal continues to be received.
262 //
263 // The specific signals used here are OS-specific.
262 a.ncCtx = a.Context 264 a.ncCtx = a.Context
263 a.Context, a.cancelFunc = context.WithCancel(a.Context) 265 a.Context, a.cancelFunc = context.WithCancel(a.Context)
264 signalC := make(chan os.Signal, 1) 266 signalC := make(chan os.Signal, 1)
265 » signal.Notify(signalC, os.Interrupt) 267 » signal.Notify(signalC, interruptSignals...)
266 go func() { 268 go func() {
267 signalled := false 269 signalled := false
268 for range signalC { 270 for range signalC {
269 if !signalled { 271 if !signalled {
270 signalled = true 272 signalled = true
271 273
272 // First '^C'; soft-terminate 274 // First '^C'; soft-terminate
273 log.Infof(a, "Flushing in response to Control-C (keyboard interrupt). Interrupt again for immediate exit.") 275 log.Infof(a, "Flushing in response to Control-C (keyboard interrupt). Interrupt again for immediate exit.")
274 a.cancelFunc() 276 a.cancelFunc()
275 } else { 277 } else {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 312
311 paniccatcher.Do(func() { 313 paniccatcher.Do(func() {
312 rc = mainImpl(ctx, os.Args[1:]) 314 rc = mainImpl(ctx, os.Args[1:])
313 }, func(p *paniccatcher.Panic) { 315 }, func(p *paniccatcher.Panic) {
314 log.Fields{ 316 log.Fields{
315 "panic.error": p.Reason, 317 "panic.error": p.Reason,
316 }.Errorf(ctx, "Panic caught in main:\n%s", p.Stack) 318 }.Errorf(ctx, "Panic caught in main:\n%s", p.Stack)
317 rc = runtimeErrorReturnCode 319 rc = runtimeErrorReturnCode
318 }) 320 })
319 } 321 }
OLDNEW
« no previous file with comments | « no previous file | client/cmd/logdog_butler/main_posix.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698