@@ -264,6 +264,10 @@ func main() {
264
264
os .Exit (127 )
265
265
}
266
266
267
+ //
268
+ // Parse and verify flags. Errors here are fatal.
269
+ //
270
+
267
271
pflag .Parse ()
268
272
flag .CommandLine .Parse (nil ) // Otherwise glog complains
269
273
setGlogFlags ()
@@ -362,11 +366,6 @@ func main() {
362
366
}
363
367
}
364
368
365
- if _ , err := exec .LookPath (* flGitCmd ); err != nil {
366
- fmt .Fprintf (os .Stderr , "ERROR: git executable %q not found: %v\n " , * flGitCmd , err )
367
- os .Exit (1 )
368
- }
369
-
370
369
if * flSSH {
371
370
if * flUsername != "" {
372
371
fmt .Fprintf (os .Stderr , "ERROR: only one of --ssh and --username may be specified\n " )
@@ -398,19 +397,30 @@ func main() {
398
397
}
399
398
}
400
399
400
+ // From here on, output goes through logging.
401
+ log .V (0 ).Info ("starting up" , "pid" , os .Getpid (), "args" , os .Args )
402
+
403
+ if _ , err := exec .LookPath (* flGitCmd ); err != nil {
404
+ log .Error (err , "ERROR: git executable not found" , "git" , * flGitCmd )
405
+ os .Exit (1 )
406
+ }
407
+
401
408
if err := os .MkdirAll (* flRoot , 0700 ); err != nil {
402
- fmt . Fprintf ( os . Stderr , "ERROR: can't make root dir: %v" , err )
409
+ log . Error ( err , "ERROR: can't make root dir" , "path" , * flRoot )
403
410
os .Exit (1 )
404
411
}
405
412
absRoot , err := normalizePath (* flRoot )
406
413
if err != nil {
407
- fmt . Fprintf ( os . Stderr , "ERROR: can't normalize root path: %v" , err )
414
+ log . Error ( err , "ERROR: can't normalize root path" , "path" , * flRoot )
408
415
os .Exit (1 )
409
416
}
417
+ if absRoot != * flRoot {
418
+ log .V (0 ).Info ("normalized root path" , "path" , * flRoot , "result" , absRoot )
419
+ }
410
420
411
421
if * flAddUser {
412
422
if err := addUser (); err != nil {
413
- fmt . Fprintf ( os . Stderr , "ERROR: can't write to /etc/passwd: %v \n " , err )
423
+ log . Error ( err , "ERROR: can't add user" )
414
424
os .Exit (1 )
415
425
}
416
426
}
@@ -421,29 +431,29 @@ func main() {
421
431
422
432
if * flUsername != "" && * flPassword != "" {
423
433
if err := setupGitAuth (ctx , * flUsername , * flPassword , * flRepo ); err != nil {
424
- fmt . Fprintf ( os . Stderr , "ERROR: can't create .netrc file: %v \n " , err )
434
+ log . Error ( err , "ERROR: can't set up git auth" )
425
435
os .Exit (1 )
426
436
}
427
437
}
428
438
429
439
if * flSSH {
430
440
if err := setupGitSSH (* flSSHKnownHosts ); err != nil {
431
- fmt . Fprintf ( os . Stderr , "ERROR: can't configure SSH: %v \n " , err )
441
+ log . Error ( err , "ERROR: can't set up git SSH" )
432
442
os .Exit (1 )
433
443
}
434
444
}
435
445
436
446
if * flCookieFile {
437
447
if err := setupGitCookieFile (ctx ); err != nil {
438
- fmt . Fprintf ( os . Stderr , "ERROR: can't set git cookie file: %v \n " , err )
448
+ log . Error ( err , "ERROR: can't set up git cookie file" )
439
449
os .Exit (1 )
440
450
}
441
451
}
442
452
443
453
if * flAskPassURL != "" {
444
454
if err := callGitAskPassURL (ctx , * flAskPassURL ); err != nil {
445
455
askpassCount .WithLabelValues (metricKeyError ).Inc ()
446
- fmt . Fprintf ( os . Stderr , "ERROR: failed to call ASKPASS callback URL: %v \n " , err )
456
+ log . Error ( err , "ERROR: failed to call ASKPASS callback URL" , "url" , * flAskPassURL )
447
457
os .Exit (1 )
448
458
}
449
459
askpassCount .WithLabelValues (metricKeySuccess ).Inc ()
@@ -455,38 +465,38 @@ func main() {
455
465
if * flHTTPBind != "" {
456
466
ln , err := net .Listen ("tcp" , * flHTTPBind )
457
467
if err != nil {
458
- fmt . Fprintf ( os . Stderr , "ERROR: unable to bind HTTP endpoint: %v \n " , err )
468
+ log . Error ( err , "ERROR: failed to bind HTTP endpoint" , "endpoint" , * flHTTPBind )
459
469
os .Exit (1 )
460
470
}
461
471
mux := http .NewServeMux ()
462
- go func () {
463
- if * flHTTPMetrics {
464
- mux .Handle ("/metrics" , promhttp .Handler ())
465
- }
472
+ if * flHTTPMetrics {
473
+ mux .Handle ("/metrics" , promhttp .Handler ())
474
+ }
466
475
467
- if * flHTTPprof {
468
- mux .HandleFunc ("/debug/pprof/" , pprof .Index )
469
- mux .HandleFunc ("/debug/pprof/cmdline" , pprof .Cmdline )
470
- mux .HandleFunc ("/debug/pprof/profile" , pprof .Profile )
471
- mux .HandleFunc ("/debug/pprof/symbol" , pprof .Symbol )
472
- mux .HandleFunc ("/debug/pprof/trace" , pprof .Trace )
473
- }
476
+ if * flHTTPprof {
477
+ mux .HandleFunc ("/debug/pprof/" , pprof .Index )
478
+ mux .HandleFunc ("/debug/pprof/cmdline" , pprof .Cmdline )
479
+ mux .HandleFunc ("/debug/pprof/profile" , pprof .Profile )
480
+ mux .HandleFunc ("/debug/pprof/symbol" , pprof .Symbol )
481
+ mux .HandleFunc ("/debug/pprof/trace" , pprof .Trace )
482
+ }
474
483
475
- // This is a dumb liveliness check endpoint. Currently this checks
476
- // nothing and will always return 200 if the process is live.
477
- mux .HandleFunc ("/" , func (w http.ResponseWriter , r * http.Request ) {
478
- if ! getRepoReady () {
479
- http .Error (w , "repo is not ready" , http .StatusServiceUnavailable )
480
- }
481
- // Otherwise success
482
- })
483
- http .Serve (ln , mux )
484
+ // This is a dumb liveliness check endpoint. Currently this checks
485
+ // nothing and will always return 200 if the process is live.
486
+ mux .HandleFunc ("/" , func (w http.ResponseWriter , r * http.Request ) {
487
+ if ! getRepoReady () {
488
+ http .Error (w , "repo is not ready" , http .StatusServiceUnavailable )
489
+ }
490
+ // Otherwise success
491
+ })
492
+ log .V (0 ).Info ("serving HTTP" , "endpoint" , * flHTTPBind )
493
+ go func () {
494
+ err := http .Serve (ln , mux )
495
+ log .Error (err , "HTTP server terminated" )
496
+ os .Exit (1 )
484
497
}()
485
498
}
486
499
487
- // From here on, output goes through logging.
488
- log .V (0 ).Info ("starting up" , "pid" , os .Getpid (), "args" , os .Args )
489
-
490
500
// Startup webhooks goroutine
491
501
var webhook * Webhook
492
502
if * flWebhookURL != "" {
0 commit comments