From 4ae57e83b3c49e83de8e24ceee3d0476201ff066 Mon Sep 17 00:00:00 2001 From: TheFox0x7 Date: Fri, 23 May 2025 22:28:00 +0200 Subject: [PATCH] install signals in main --- cmd/actions.go | 5 +-- cmd/admin.go | 5 +-- cmd/admin_auth.go | 10 ++---- cmd/admin_auth_ldap.go | 20 +++--------- cmd/admin_auth_oauth.go | 10 ++---- cmd/admin_auth_smtp.go | 10 ++---- cmd/admin_regenerate.go | 10 ++---- cmd/admin_user_change_password.go | 5 +-- cmd/admin_user_create.go | 3 -- cmd/admin_user_delete.go | 5 +-- cmd/admin_user_generate_access_token.go | 5 +-- cmd/admin_user_list.go | 5 +-- cmd/admin_user_must_change_password.go | 5 +-- cmd/doctor.go | 16 +++------- cmd/doctor_convert.go | 7 ++--- cmd/dump.go | 7 ++--- cmd/dump_repo.go | 7 ++--- cmd/hook.go | 14 ++------- cmd/keys.go | 5 +-- cmd/mailer.go | 5 +-- cmd/main.go | 4 ++- cmd/manager.go | 25 +++------------ cmd/manager_logging.go | 42 ++++++------------------- cmd/migrate.go | 7 ++--- cmd/migrate_storage.go | 15 ++++----- cmd/restore_repo.go | 5 +-- cmd/serv.go | 5 +-- contrib/backport/backport.go | 10 +++--- 28 files changed, 67 insertions(+), 205 deletions(-) diff --git a/cmd/actions.go b/cmd/actions.go index 240e17f35e..2c51c6a1bc 100644 --- a/cmd/actions.go +++ b/cmd/actions.go @@ -39,10 +39,7 @@ var ( } ) -func runGenerateActionsRunnerToken(_ context.Context, c *cli.Command) error { - ctx, cancel := installSignals() - defer cancel() - +func runGenerateActionsRunnerToken(ctx context.Context, c *cli.Command) error { setting.MustInstalled() scope := c.String("scope") diff --git a/cmd/admin.go b/cmd/admin.go index cdd7a4c2e1..c38357625e 100644 --- a/cmd/admin.go +++ b/cmd/admin.go @@ -93,10 +93,7 @@ var ( } ) -func runRepoSyncReleases(_ context.Context, _ *cli.Command) error { - ctx, cancel := installSignals() - defer cancel() - +func runRepoSyncReleases(ctx context.Context, _ *cli.Command) error { if err := initDB(ctx); err != nil { return err } diff --git a/cmd/admin_auth.go b/cmd/admin_auth.go index eff1532b2f..eefa981428 100644 --- a/cmd/admin_auth.go +++ b/cmd/admin_auth.go @@ -57,10 +57,7 @@ var ( } ) -func runListAuth(_ context.Context, c *cli.Command) error { - ctx, cancel := installSignals() - defer cancel() - +func runListAuth(ctx context.Context, c *cli.Command) error { if err := initDB(ctx); err != nil { return err } @@ -91,14 +88,11 @@ func runListAuth(_ context.Context, c *cli.Command) error { return nil } -func runDeleteAuth(_ context.Context, c *cli.Command) error { +func runDeleteAuth(ctx context.Context, c *cli.Command) error { if !c.IsSet("id") { return errors.New("--id flag is missing") } - ctx, cancel := installSignals() - defer cancel() - if err := initDB(ctx); err != nil { return err } diff --git a/cmd/admin_auth_ldap.go b/cmd/admin_auth_ldap.go index 57f06175da..80786282e8 100644 --- a/cmd/admin_auth_ldap.go +++ b/cmd/admin_auth_ldap.go @@ -328,10 +328,7 @@ func (a *authService) getAuthSource(ctx context.Context, c *cli.Command, authTyp } // addLdapBindDn adds a new LDAP via Bind DN authentication source. -func (a *authService) addLdapBindDn(_ context.Context, c *cli.Command) error { - ctx, cancel := installSignals() - defer cancel() - +func (a *authService) addLdapBindDn(ctx context.Context, c *cli.Command) error { if err := a.initDB(ctx); err != nil { return err } @@ -353,10 +350,7 @@ func (a *authService) addLdapBindDn(_ context.Context, c *cli.Command) error { } // updateLdapBindDn updates a new LDAP via Bind DN authentication source. -func (a *authService) updateLdapBindDn(_ context.Context, c *cli.Command) error { - ctx, cancel := installSignals() - defer cancel() - +func (a *authService) updateLdapBindDn(ctx context.Context, c *cli.Command) error { if err := a.initDB(ctx); err != nil { return err } @@ -375,10 +369,7 @@ func (a *authService) updateLdapBindDn(_ context.Context, c *cli.Command) error } // addLdapSimpleAuth adds a new LDAP (simple auth) authentication source. -func (a *authService) addLdapSimpleAuth(_ context.Context, c *cli.Command) error { - ctx, cancel := installSignals() - defer cancel() - +func (a *authService) addLdapSimpleAuth(ctx context.Context, c *cli.Command) error { if err := a.initDB(ctx); err != nil { return err } @@ -400,10 +391,7 @@ func (a *authService) addLdapSimpleAuth(_ context.Context, c *cli.Command) error } // updateLdapSimpleAuth updates a new LDAP (simple auth) authentication source. -func (a *authService) updateLdapSimpleAuth(_ context.Context, c *cli.Command) error { - ctx, cancel := installSignals() - defer cancel() - +func (a *authService) updateLdapSimpleAuth(ctx context.Context, c *cli.Command) error { if err := a.initDB(ctx); err != nil { return err } diff --git a/cmd/admin_auth_oauth.go b/cmd/admin_auth_oauth.go index 02152a084b..05af1c3a20 100644 --- a/cmd/admin_auth_oauth.go +++ b/cmd/admin_auth_oauth.go @@ -176,10 +176,7 @@ func parseOAuth2Config(c *cli.Command) *oauth2.Source { } } -func (a *authService) runAddOauth(_ context.Context, c *cli.Command) error { - ctx, cancel := installSignals() - defer cancel() - +func (a *authService) runAddOauth(ctx context.Context, c *cli.Command) error { if err := a.initDB(ctx); err != nil { return err } @@ -201,14 +198,11 @@ func (a *authService) runAddOauth(_ context.Context, c *cli.Command) error { }) } -func (a *authService) runUpdateOauth(_ context.Context, c *cli.Command) error { +func (a *authService) runUpdateOauth(ctx context.Context, c *cli.Command) error { if !c.IsSet("id") { return errors.New("--id flag is missing") } - ctx, cancel := installSignals() - defer cancel() - if err := a.initDB(ctx); err != nil { return err } diff --git a/cmd/admin_auth_smtp.go b/cmd/admin_auth_smtp.go index ad6b987154..457aa2f5c0 100644 --- a/cmd/admin_auth_smtp.go +++ b/cmd/admin_auth_smtp.go @@ -129,10 +129,7 @@ func parseSMTPConfig(c *cli.Command, conf *smtp.Source) error { return nil } -func (a *authService) runAddSMTP(_ context.Context, c *cli.Command) error { - ctx, cancel := installSignals() - defer cancel() - +func (a *authService) runAddSMTP(ctx context.Context, c *cli.Command) error { if err := a.initDB(ctx); err != nil { return err } @@ -171,14 +168,11 @@ func (a *authService) runAddSMTP(_ context.Context, c *cli.Command) error { }) } -func (a *authService) runUpdateSMTP(_ context.Context, c *cli.Command) error { +func (a *authService) runUpdateSMTP(ctx context.Context, c *cli.Command) error { if !c.IsSet("id") { return errors.New("--id flag is missing") } - ctx, cancel := installSignals() - defer cancel() - if err := a.initDB(ctx); err != nil { return err } diff --git a/cmd/admin_regenerate.go b/cmd/admin_regenerate.go index a5c93364f8..a5f1bd5105 100644 --- a/cmd/admin_regenerate.go +++ b/cmd/admin_regenerate.go @@ -27,20 +27,14 @@ var ( } ) -func runRegenerateHooks(_ context.Context, _ *cli.Command) error { - ctx, cancel := installSignals() - defer cancel() - +func runRegenerateHooks(ctx context.Context, _ *cli.Command) error { if err := initDB(ctx); err != nil { return err } return repo_service.SyncRepositoryHooks(graceful.GetManager().ShutdownContext()) } -func runRegenerateKeys(_ context.Context, _ *cli.Command) error { - ctx, cancel := installSignals() - defer cancel() - +func runRegenerateKeys(ctx context.Context, _ *cli.Command) error { if err := initDB(ctx); err != nil { return err } diff --git a/cmd/admin_user_change_password.go b/cmd/admin_user_change_password.go index f7c05ad647..3c4357ec0a 100644 --- a/cmd/admin_user_change_password.go +++ b/cmd/admin_user_change_password.go @@ -42,14 +42,11 @@ var microcmdUserChangePassword = &cli.Command{ }, } -func runChangePassword(_ context.Context, c *cli.Command) error { +func runChangePassword(ctx context.Context, c *cli.Command) error { if err := argsSet(c, "username", "password"); err != nil { return err } - ctx, cancel := installSignals() - defer cancel() - if err := initDB(ctx); err != nil { return err } diff --git a/cmd/admin_user_create.go b/cmd/admin_user_create.go index 28103c3d42..4f68c932e0 100644 --- a/cmd/admin_user_create.go +++ b/cmd/admin_user_create.go @@ -140,9 +140,6 @@ func runCreateUser(ctx context.Context, c *cli.Command) error { if !setting.IsInTesting { // FIXME: need to refactor the "installSignals/initDB" related code later // it doesn't make sense to call it in (almost) every command action function - var cancel context.CancelFunc - ctx, cancel = installSignals() - defer cancel() if err := initDB(ctx); err != nil { return err } diff --git a/cmd/admin_user_delete.go b/cmd/admin_user_delete.go index 18317622cf..6fe1213d41 100644 --- a/cmd/admin_user_delete.go +++ b/cmd/admin_user_delete.go @@ -42,14 +42,11 @@ var microcmdUserDelete = &cli.Command{ Action: runDeleteUser, } -func runDeleteUser(_ context.Context, c *cli.Command) error { +func runDeleteUser(ctx context.Context, c *cli.Command) error { if !c.IsSet("id") && !c.IsSet("username") && !c.IsSet("email") { return errors.New("You must provide the id, username or email of a user to delete") } - ctx, cancel := installSignals() - defer cancel() - if err := initDB(ctx); err != nil { return err } diff --git a/cmd/admin_user_generate_access_token.go b/cmd/admin_user_generate_access_token.go index 901ac5e1cb..61064fdef4 100644 --- a/cmd/admin_user_generate_access_token.go +++ b/cmd/admin_user_generate_access_token.go @@ -42,14 +42,11 @@ var microcmdUserGenerateAccessToken = &cli.Command{ Action: runGenerateAccessToken, } -func runGenerateAccessToken(_ context.Context, c *cli.Command) error { +func runGenerateAccessToken(ctx context.Context, c *cli.Command) error { if !c.IsSet("username") { return errors.New("you must provide a username to generate a token for") } - ctx, cancel := installSignals() - defer cancel() - if err := initDB(ctx); err != nil { return err } diff --git a/cmd/admin_user_list.go b/cmd/admin_user_list.go index ec214345fc..e3d345e2f2 100644 --- a/cmd/admin_user_list.go +++ b/cmd/admin_user_list.go @@ -26,10 +26,7 @@ var microcmdUserList = &cli.Command{ }, } -func runListUsers(_ context.Context, c *cli.Command) error { - ctx, cancel := installSignals() - defer cancel() - +func runListUsers(ctx context.Context, c *cli.Command) error { if err := initDB(ctx); err != nil { return err } diff --git a/cmd/admin_user_must_change_password.go b/cmd/admin_user_must_change_password.go index ddc82af416..677477ca92 100644 --- a/cmd/admin_user_must_change_password.go +++ b/cmd/admin_user_must_change_password.go @@ -35,10 +35,7 @@ var microcmdUserMustChangePassword = &cli.Command{ }, } -func runMustChangePassword(_ context.Context, c *cli.Command) error { - ctx, cancel := installSignals() - defer cancel() - +func runMustChangePassword(ctx context.Context, c *cli.Command) error { if c.NArg() == 0 && !c.IsSet("all") { return errors.New("either usernames or --all must be provided") } diff --git a/cmd/doctor.go b/cmd/doctor.go index 688793bcfa..9e0fcbf877 100644 --- a/cmd/doctor.go +++ b/cmd/doctor.go @@ -93,10 +93,7 @@ You should back-up your database before doing this and ensure that your database Action: runRecreateTable, } -func runRecreateTable(_ context.Context, cmd *cli.Command) error { - stdCtx, cancel := installSignals() - defer cancel() - +func runRecreateTable(ctx context.Context, cmd *cli.Command) error { // Redirect the default golog to here golog.SetFlags(0) golog.SetPrefix("") @@ -113,7 +110,7 @@ func runRecreateTable(_ context.Context, cmd *cli.Command) error { } setting.Database.LogSQL = debug - if err := db.InitEngine(stdCtx); err != nil { + if err := db.InitEngine(ctx); err != nil { fmt.Println(err) fmt.Println("Check if you are using the right config file. You can use a --config directive to specify one.") return nil @@ -131,7 +128,7 @@ func runRecreateTable(_ context.Context, cmd *cli.Command) error { } recreateTables := migrate_base.RecreateTables(beans...) - return db.InitEngineWithMigration(stdCtx, func(ctx context.Context, x *xorm.Engine) error { + return db.InitEngineWithMigration(ctx, func(ctx context.Context, x *xorm.Engine) error { if err := migrations.EnsureUpToDate(ctx, x); err != nil { return err } @@ -161,10 +158,7 @@ func setupDoctorDefaultLogger(cmd *cli.Command, colorize bool) { } } -func runDoctorCheck(_ context.Context, cmd *cli.Command) error { - stdCtx, cancel := installSignals() - defer cancel() - +func runDoctorCheck(ctx context.Context, cmd *cli.Command) error { colorize := log.CanColorStdout if cmd.IsSet("color") { colorize = cmd.Bool("color") @@ -217,5 +211,5 @@ func runDoctorCheck(_ context.Context, cmd *cli.Command) error { } } } - return doctor.RunChecks(stdCtx, colorize, cmd.Bool("fix"), checks) + return doctor.RunChecks(ctx, colorize, cmd.Bool("fix"), checks) } diff --git a/cmd/doctor_convert.go b/cmd/doctor_convert.go index deb989128e..8cb718d383 100644 --- a/cmd/doctor_convert.go +++ b/cmd/doctor_convert.go @@ -22,11 +22,8 @@ var cmdDoctorConvert = &cli.Command{ Action: runDoctorConvert, } -func runDoctorConvert(_ context.Context, cmd *cli.Command) error { - stdCtx, cancel := installSignals() - defer cancel() - - if err := initDB(stdCtx); err != nil { +func runDoctorConvert(ctx context.Context, cmd *cli.Command) error { + if err := initDB(ctx); err != nil { return err } diff --git a/cmd/dump.go b/cmd/dump.go index 8ae278bd70..ed19e3d4bf 100644 --- a/cmd/dump.go +++ b/cmd/dump.go @@ -102,7 +102,7 @@ func fatal(format string, args ...any) { log.Fatal(format, args...) } -func runDump(_ context.Context, cmd *cli.Command) error { +func runDump(ctx context.Context, cmd *cli.Command) error { setting.MustInstalled() quite := cmd.Bool("quiet") @@ -137,10 +137,7 @@ func runDump(_ context.Context, cmd *cli.Command) error { setting.DisableLoggerInit() setting.LoadSettings() // cannot access session settings otherwise - stdCtx, cancel := installSignals() - defer cancel() - - err := db.InitEngine(stdCtx) + err := db.InitEngine(ctx) if err != nil { return err } diff --git a/cmd/dump_repo.go b/cmd/dump_repo.go index 4b125e5f69..ae25ad2d79 100644 --- a/cmd/dump_repo.go +++ b/cmd/dump_repo.go @@ -79,11 +79,8 @@ wiki, issues, labels, releases, release_assets, milestones, pull_requests, comme }, } -func runDumpRepository(_ context.Context, cmd *cli.Command) error { - stdCtx, cancel := installSignals() - defer cancel() - - if err := initDB(stdCtx); err != nil { +func runDumpRepository(ctx context.Context, cmd *cli.Command) error { + if err := initDB(ctx); err != nil { return err } diff --git a/cmd/hook.go b/cmd/hook.go index 7a9f8c84a4..b9e9f87815 100644 --- a/cmd/hook.go +++ b/cmd/hook.go @@ -161,12 +161,10 @@ func (n *nilWriter) WriteString(s string) (int, error) { return len(s), nil } -func runHookPreReceive(_ context.Context, c *cli.Command) error { +func runHookPreReceive(ctx context.Context, c *cli.Command) error { if isInternal, _ := strconv.ParseBool(os.Getenv(repo_module.EnvIsInternal)); isInternal { return nil } - ctx, cancel := installSignals() - defer cancel() setup(ctx, c.Bool("debug")) @@ -309,10 +307,7 @@ func runHookUpdate(_ context.Context, c *cli.Command) error { return nil } -func runHookPostReceive(_ context.Context, c *cli.Command) error { - ctx, cancel := installSignals() - defer cancel() - +func runHookPostReceive(ctx context.Context, c *cli.Command) error { setup(ctx, c.Bool("debug")) // First of all run update-server-info no matter what @@ -496,10 +491,7 @@ func pushOptions() map[string]string { return opts } -func runHookProcReceive(_ context.Context, c *cli.Command) error { - ctx, cancel := installSignals() - defer cancel() - +func runHookProcReceive(ctx context.Context, c *cli.Command) error { setup(ctx, c.Bool("debug")) if len(os.Getenv("SSH_ORIGINAL_COMMAND")) == 0 { diff --git a/cmd/keys.go b/cmd/keys.go index a63025be6b..759932f1e9 100644 --- a/cmd/keys.go +++ b/cmd/keys.go @@ -50,7 +50,7 @@ var CmdKeys = &cli.Command{ }, } -func runKeys(_ context.Context, c *cli.Command) error { +func runKeys(ctx context.Context, c *cli.Command) error { if !c.IsSet("username") { return errors.New("No username provided") } @@ -69,9 +69,6 @@ func runKeys(_ context.Context, c *cli.Command) error { return errors.New("No key type and content provided") } - ctx, cancel := installSignals() - defer cancel() - setup(ctx, c.Bool("debug")) authorizedString, extra := private.AuthorizedPublicKeyByContent(ctx, content) diff --git a/cmd/mailer.go b/cmd/mailer.go index 7721c8db91..e0bbd91ad6 100644 --- a/cmd/mailer.go +++ b/cmd/mailer.go @@ -13,10 +13,7 @@ import ( "github.com/urfave/cli/v3" ) -func runSendMail(_ context.Context, c *cli.Command) error { - ctx, cancel := installSignals() - defer cancel() - +func runSendMail(ctx context.Context, c *cli.Command) error { setting.MustInstalled() if err := argsSet(c, "title"); err != nil { diff --git a/cmd/main.go b/cmd/main.go index 31ff9c9a5b..d086fda275 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -173,7 +173,9 @@ func NewMainApp(appVer AppVersion) *cli.Command { } func RunMainApp(app *cli.Command, args ...string) error { - err := app.Run(context.Background(), args) + ctx, cancel := installSignals() + defer cancel() + err := app.Run(ctx, args) if err == nil { return nil } diff --git a/cmd/manager.go b/cmd/manager.go index c4b07e4f1c..f0935ea065 100644 --- a/cmd/manager.go +++ b/cmd/manager.go @@ -109,46 +109,31 @@ var ( } ) -func runShutdown(_ context.Context, c *cli.Command) error { - ctx, cancel := installSignals() - defer cancel() - +func runShutdown(ctx context.Context, c *cli.Command) error { setup(ctx, c.Bool("debug")) extra := private.Shutdown(ctx) return handleCliResponseExtra(extra) } -func runRestart(_ context.Context, c *cli.Command) error { - ctx, cancel := installSignals() - defer cancel() - +func runRestart(ctx context.Context, c *cli.Command) error { setup(ctx, c.Bool("debug")) extra := private.Restart(ctx) return handleCliResponseExtra(extra) } -func runReloadTemplates(_ context.Context, c *cli.Command) error { - ctx, cancel := installSignals() - defer cancel() - +func runReloadTemplates(ctx context.Context, c *cli.Command) error { setup(ctx, c.Bool("debug")) extra := private.ReloadTemplates(ctx) return handleCliResponseExtra(extra) } -func runFlushQueues(_ context.Context, c *cli.Command) error { - ctx, cancel := installSignals() - defer cancel() - +func runFlushQueues(ctx context.Context, c *cli.Command) error { setup(ctx, c.Bool("debug")) extra := private.FlushQueues(ctx, c.Duration("timeout"), c.Bool("non-blocking")) return handleCliResponseExtra(extra) } -func runProcesses(_ context.Context, c *cli.Command) error { - ctx, cancel := installSignals() - defer cancel() - +func runProcesses(ctx context.Context, c *cli.Command) error { setup(ctx, c.Bool("debug")) extra := private.Processes(ctx, os.Stdout, c.Bool("flat"), c.Bool("no-system"), c.Bool("stacktraces"), c.Bool("json"), c.String("cancel")) return handleCliResponseExtra(extra) diff --git a/cmd/manager_logging.go b/cmd/manager_logging.go index cb54ebb5c4..c83073e9c6 100644 --- a/cmd/manager_logging.go +++ b/cmd/manager_logging.go @@ -196,10 +196,7 @@ var ( } ) -func runRemoveLogger(_ context.Context, c *cli.Command) error { - ctx, cancel := installSignals() - defer cancel() - +func runRemoveLogger(ctx context.Context, c *cli.Command) error { setup(ctx, c.Bool("debug")) logger := c.String("logger") if len(logger) == 0 { @@ -211,10 +208,7 @@ func runRemoveLogger(_ context.Context, c *cli.Command) error { return handleCliResponseExtra(extra) } -func runAddConnLogger(_ context.Context, c *cli.Command) error { - ctx, cancel := installSignals() - defer cancel() - +func runAddConnLogger(ctx context.Context, c *cli.Command) error { setup(ctx, c.Bool("debug")) vals := map[string]any{} mode := "conn" @@ -238,13 +232,10 @@ func runAddConnLogger(_ context.Context, c *cli.Command) error { if c.IsSet("reconnect-on-message") { vals["reconnectOnMsg"] = c.Bool("reconnect-on-message") } - return commonAddLogger(c, mode, vals) + return commonAddLogger(ctx, c, mode, vals) } -func runAddFileLogger(_ context.Context, c *cli.Command) error { - ctx, cancel := installSignals() - defer cancel() - +func runAddFileLogger(ctx context.Context, c *cli.Command) error { setup(ctx, c.Bool("debug")) vals := map[string]any{} mode := "file" @@ -271,10 +262,10 @@ func runAddFileLogger(_ context.Context, c *cli.Command) error { if c.IsSet("compression-level") { vals["compressionLevel"] = c.Int("compression-level") } - return commonAddLogger(c, mode, vals) + return commonAddLogger(ctx, c, mode, vals) } -func commonAddLogger(c *cli.Command, mode string, vals map[string]any) error { +func commonAddLogger(ctx context.Context, c *cli.Command, mode string, vals map[string]any) error { if len(c.String("level")) > 0 { vals["level"] = log.LevelFromString(c.String("level")).String() } @@ -301,46 +292,33 @@ func commonAddLogger(c *cli.Command, mode string, vals map[string]any) error { if c.IsSet("writer") { writer = c.String("writer") } - ctx, cancel := installSignals() - defer cancel() extra := private.AddLogger(ctx, logger, writer, mode, vals) return handleCliResponseExtra(extra) } -func runPauseLogging(_ context.Context, c *cli.Command) error { - ctx, cancel := installSignals() - defer cancel() - +func runPauseLogging(ctx context.Context, c *cli.Command) error { setup(ctx, c.Bool("debug")) userMsg := private.PauseLogging(ctx) _, _ = fmt.Fprintln(os.Stdout, userMsg) return nil } -func runResumeLogging(_ context.Context, c *cli.Command) error { - ctx, cancel := installSignals() - defer cancel() - +func runResumeLogging(ctx context.Context, c *cli.Command) error { setup(ctx, c.Bool("debug")) userMsg := private.ResumeLogging(ctx) _, _ = fmt.Fprintln(os.Stdout, userMsg) return nil } -func runReleaseReopenLogging(_ context.Context, c *cli.Command) error { - ctx, cancel := installSignals() - defer cancel() - +func runReleaseReopenLogging(ctx context.Context, c *cli.Command) error { setup(ctx, c.Bool("debug")) userMsg := private.ReleaseReopenLogging(ctx) _, _ = fmt.Fprintln(os.Stdout, userMsg) return nil } -func runSetLogSQL(_ context.Context, c *cli.Command) error { - ctx, cancel := installSignals() - defer cancel() +func runSetLogSQL(ctx context.Context, c *cli.Command) error { setup(ctx, c.Bool("debug")) extra := private.SetLogSQL(ctx, !c.Bool("off")) diff --git a/cmd/migrate.go b/cmd/migrate.go index 8b7653a980..e24dc9e572 100644 --- a/cmd/migrate.go +++ b/cmd/migrate.go @@ -22,11 +22,8 @@ var CmdMigrate = &cli.Command{ Action: runMigrate, } -func runMigrate(_ context.Context, c *cli.Command) error { - stdCtx, cancel := installSignals() - defer cancel() - - if err := initDB(stdCtx); err != nil { +func runMigrate(ctx context.Context, c *cli.Command) error { + if err := initDB(ctx); err != nil { return err } diff --git a/cmd/migrate_storage.go b/cmd/migrate_storage.go index af83aee80c..2c63e15f50 100644 --- a/cmd/migrate_storage.go +++ b/cmd/migrate_storage.go @@ -213,11 +213,8 @@ func migrateActionsArtifacts(ctx context.Context, dstStorage storage.ObjectStora }) } -func runMigrateStorage(_ context.Context, cmd *cli.Command) error { - stdCtx, cancel := installSignals() - defer cancel() - - if err := initDB(stdCtx); err != nil { +func runMigrateStorage(ctx context.Context, cmd *cli.Command) error { + if err := initDB(ctx); err != nil { return err } @@ -248,13 +245,13 @@ func runMigrateStorage(_ context.Context, cmd *cli.Command) error { return nil } dstStorage, err = storage.NewLocalStorage( - stdCtx, + ctx, &setting.Storage{ Path: p, }) case string(setting.MinioStorageType): dstStorage, err = storage.NewMinioStorage( - stdCtx, + ctx, &setting.Storage{ MinioConfig: setting.MinioStorageConfig{ Endpoint: cmd.String("minio-endpoint"), @@ -271,7 +268,7 @@ func runMigrateStorage(_ context.Context, cmd *cli.Command) error { }) case string(setting.AzureBlobStorageType): dstStorage, err = storage.NewAzureBlobStorage( - stdCtx, + ctx, &setting.Storage{ AzureBlobConfig: setting.AzureBlobStorageConfig{ Endpoint: cmd.String("azureblob-endpoint"), @@ -301,7 +298,7 @@ func runMigrateStorage(_ context.Context, cmd *cli.Command) error { tp := strings.ToLower(cmd.String("type")) if m, ok := migratedMethods[tp]; ok { - if err := m(stdCtx, dstStorage); err != nil { + if err := m(ctx, dstStorage); err != nil { return err } log.Info("%s files have successfully been copied to the new storage.", tp) diff --git a/cmd/restore_repo.go b/cmd/restore_repo.go index 238789615f..c61f5a582e 100644 --- a/cmd/restore_repo.go +++ b/cmd/restore_repo.go @@ -49,10 +49,7 @@ wiki, issues, labels, releases, release_assets, milestones, pull_requests, comme }, } -func runRestoreRepository(_ context.Context, c *cli.Command) error { - ctx, cancel := installSignals() - defer cancel() - +func runRestoreRepository(ctx context.Context, c *cli.Command) error { setting.MustInstalled() var units []string if s := c.String("units"); s != "" { diff --git a/cmd/serv.go b/cmd/serv.go index 9f5665c668..e4434450d6 100644 --- a/cmd/serv.go +++ b/cmd/serv.go @@ -152,10 +152,7 @@ func getLFSAuthToken(ctx context.Context, lfsVerb string, results *private.ServC return "Bearer " + tokenString, nil } -func runServ(_ context.Context, c *cli.Command) error { - ctx, cancel := installSignals() - defer cancel() - +func runServ(ctx context.Context, c *cli.Command) error { // FIXME: This needs to internationalised setup(ctx, c.Bool("debug")) diff --git a/contrib/backport/backport.go b/contrib/backport/backport.go index e0f21e451d..9e7a78dab5 100644 --- a/contrib/backport/backport.go +++ b/contrib/backport/backport.go @@ -105,16 +105,14 @@ OPTIONS: ` app.Action = runBackport - - if err := app.Run(context.Background(), os.Args); err != nil { + ctx, cancel := installSignals() + defer cancel() + if err := app.Run(ctx, os.Args); err != nil { fmt.Fprintf(os.Stderr, "Unable to backport: %v\n", err) } } -func runBackport(_ context.Context, c *cli.Command) error { - ctx, cancel := installSignals() - defer cancel() - +func runBackport(ctx context.Context, c *cli.Command) error { continuing := c.Bool("continue") var pr string