0
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-07-21 01:38:30 +02:00

install signals in main

This commit is contained in:
TheFox0x7 2025-05-23 22:28:00 +02:00
parent 69cde4d79a
commit 4ae57e83b3
No known key found for this signature in database
GPG Key ID: 6CA33903484AF7C2
28 changed files with 67 additions and 205 deletions

View File

@ -39,10 +39,7 @@ var (
} }
) )
func runGenerateActionsRunnerToken(_ context.Context, c *cli.Command) error { func runGenerateActionsRunnerToken(ctx context.Context, c *cli.Command) error {
ctx, cancel := installSignals()
defer cancel()
setting.MustInstalled() setting.MustInstalled()
scope := c.String("scope") scope := c.String("scope")

View File

@ -93,10 +93,7 @@ var (
} }
) )
func runRepoSyncReleases(_ context.Context, _ *cli.Command) error { func runRepoSyncReleases(ctx context.Context, _ *cli.Command) error {
ctx, cancel := installSignals()
defer cancel()
if err := initDB(ctx); err != nil { if err := initDB(ctx); err != nil {
return err return err
} }

View File

@ -57,10 +57,7 @@ var (
} }
) )
func runListAuth(_ context.Context, c *cli.Command) error { func runListAuth(ctx context.Context, c *cli.Command) error {
ctx, cancel := installSignals()
defer cancel()
if err := initDB(ctx); err != nil { if err := initDB(ctx); err != nil {
return err return err
} }
@ -91,14 +88,11 @@ func runListAuth(_ context.Context, c *cli.Command) error {
return nil return nil
} }
func runDeleteAuth(_ context.Context, c *cli.Command) error { func runDeleteAuth(ctx context.Context, c *cli.Command) error {
if !c.IsSet("id") { if !c.IsSet("id") {
return errors.New("--id flag is missing") return errors.New("--id flag is missing")
} }
ctx, cancel := installSignals()
defer cancel()
if err := initDB(ctx); err != nil { if err := initDB(ctx); err != nil {
return err return err
} }

View File

@ -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. // addLdapBindDn adds a new LDAP via Bind DN authentication source.
func (a *authService) addLdapBindDn(_ context.Context, c *cli.Command) error { func (a *authService) addLdapBindDn(ctx context.Context, c *cli.Command) error {
ctx, cancel := installSignals()
defer cancel()
if err := a.initDB(ctx); err != nil { if err := a.initDB(ctx); err != nil {
return err 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. // updateLdapBindDn updates a new LDAP via Bind DN authentication source.
func (a *authService) updateLdapBindDn(_ context.Context, c *cli.Command) error { func (a *authService) updateLdapBindDn(ctx context.Context, c *cli.Command) error {
ctx, cancel := installSignals()
defer cancel()
if err := a.initDB(ctx); err != nil { if err := a.initDB(ctx); err != nil {
return err 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. // addLdapSimpleAuth adds a new LDAP (simple auth) authentication source.
func (a *authService) addLdapSimpleAuth(_ context.Context, c *cli.Command) error { func (a *authService) addLdapSimpleAuth(ctx context.Context, c *cli.Command) error {
ctx, cancel := installSignals()
defer cancel()
if err := a.initDB(ctx); err != nil { if err := a.initDB(ctx); err != nil {
return err 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. // updateLdapSimpleAuth updates a new LDAP (simple auth) authentication source.
func (a *authService) updateLdapSimpleAuth(_ context.Context, c *cli.Command) error { func (a *authService) updateLdapSimpleAuth(ctx context.Context, c *cli.Command) error {
ctx, cancel := installSignals()
defer cancel()
if err := a.initDB(ctx); err != nil { if err := a.initDB(ctx); err != nil {
return err return err
} }

View File

@ -176,10 +176,7 @@ func parseOAuth2Config(c *cli.Command) *oauth2.Source {
} }
} }
func (a *authService) runAddOauth(_ context.Context, c *cli.Command) error { func (a *authService) runAddOauth(ctx context.Context, c *cli.Command) error {
ctx, cancel := installSignals()
defer cancel()
if err := a.initDB(ctx); err != nil { if err := a.initDB(ctx); err != nil {
return err 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") { if !c.IsSet("id") {
return errors.New("--id flag is missing") return errors.New("--id flag is missing")
} }
ctx, cancel := installSignals()
defer cancel()
if err := a.initDB(ctx); err != nil { if err := a.initDB(ctx); err != nil {
return err return err
} }

View File

@ -129,10 +129,7 @@ func parseSMTPConfig(c *cli.Command, conf *smtp.Source) error {
return nil return nil
} }
func (a *authService) runAddSMTP(_ context.Context, c *cli.Command) error { func (a *authService) runAddSMTP(ctx context.Context, c *cli.Command) error {
ctx, cancel := installSignals()
defer cancel()
if err := a.initDB(ctx); err != nil { if err := a.initDB(ctx); err != nil {
return err 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") { if !c.IsSet("id") {
return errors.New("--id flag is missing") return errors.New("--id flag is missing")
} }
ctx, cancel := installSignals()
defer cancel()
if err := a.initDB(ctx); err != nil { if err := a.initDB(ctx); err != nil {
return err return err
} }

View File

@ -27,20 +27,14 @@ var (
} }
) )
func runRegenerateHooks(_ context.Context, _ *cli.Command) error { func runRegenerateHooks(ctx context.Context, _ *cli.Command) error {
ctx, cancel := installSignals()
defer cancel()
if err := initDB(ctx); err != nil { if err := initDB(ctx); err != nil {
return err return err
} }
return repo_service.SyncRepositoryHooks(graceful.GetManager().ShutdownContext()) return repo_service.SyncRepositoryHooks(graceful.GetManager().ShutdownContext())
} }
func runRegenerateKeys(_ context.Context, _ *cli.Command) error { func runRegenerateKeys(ctx context.Context, _ *cli.Command) error {
ctx, cancel := installSignals()
defer cancel()
if err := initDB(ctx); err != nil { if err := initDB(ctx); err != nil {
return err return err
} }

View File

@ -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 { if err := argsSet(c, "username", "password"); err != nil {
return err return err
} }
ctx, cancel := installSignals()
defer cancel()
if err := initDB(ctx); err != nil { if err := initDB(ctx); err != nil {
return err return err
} }

View File

@ -140,9 +140,6 @@ func runCreateUser(ctx context.Context, c *cli.Command) error {
if !setting.IsInTesting { if !setting.IsInTesting {
// FIXME: need to refactor the "installSignals/initDB" related code later // FIXME: need to refactor the "installSignals/initDB" related code later
// it doesn't make sense to call it in (almost) every command action function // 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 { if err := initDB(ctx); err != nil {
return err return err
} }

View File

@ -42,14 +42,11 @@ var microcmdUserDelete = &cli.Command{
Action: runDeleteUser, 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") { 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") 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 { if err := initDB(ctx); err != nil {
return err return err
} }

View File

@ -42,14 +42,11 @@ var microcmdUserGenerateAccessToken = &cli.Command{
Action: runGenerateAccessToken, Action: runGenerateAccessToken,
} }
func runGenerateAccessToken(_ context.Context, c *cli.Command) error { func runGenerateAccessToken(ctx context.Context, c *cli.Command) error {
if !c.IsSet("username") { if !c.IsSet("username") {
return errors.New("you must provide a username to generate a token for") return errors.New("you must provide a username to generate a token for")
} }
ctx, cancel := installSignals()
defer cancel()
if err := initDB(ctx); err != nil { if err := initDB(ctx); err != nil {
return err return err
} }

View File

@ -26,10 +26,7 @@ var microcmdUserList = &cli.Command{
}, },
} }
func runListUsers(_ context.Context, c *cli.Command) error { func runListUsers(ctx context.Context, c *cli.Command) error {
ctx, cancel := installSignals()
defer cancel()
if err := initDB(ctx); err != nil { if err := initDB(ctx); err != nil {
return err return err
} }

View File

@ -35,10 +35,7 @@ var microcmdUserMustChangePassword = &cli.Command{
}, },
} }
func runMustChangePassword(_ context.Context, c *cli.Command) error { func runMustChangePassword(ctx context.Context, c *cli.Command) error {
ctx, cancel := installSignals()
defer cancel()
if c.NArg() == 0 && !c.IsSet("all") { if c.NArg() == 0 && !c.IsSet("all") {
return errors.New("either usernames or --all must be provided") return errors.New("either usernames or --all must be provided")
} }

View File

@ -93,10 +93,7 @@ You should back-up your database before doing this and ensure that your database
Action: runRecreateTable, Action: runRecreateTable,
} }
func runRecreateTable(_ context.Context, cmd *cli.Command) error { func runRecreateTable(ctx context.Context, cmd *cli.Command) error {
stdCtx, cancel := installSignals()
defer cancel()
// Redirect the default golog to here // Redirect the default golog to here
golog.SetFlags(0) golog.SetFlags(0)
golog.SetPrefix("") golog.SetPrefix("")
@ -113,7 +110,7 @@ func runRecreateTable(_ context.Context, cmd *cli.Command) error {
} }
setting.Database.LogSQL = debug setting.Database.LogSQL = debug
if err := db.InitEngine(stdCtx); err != nil { if err := db.InitEngine(ctx); err != nil {
fmt.Println(err) fmt.Println(err)
fmt.Println("Check if you are using the right config file. You can use a --config directive to specify one.") fmt.Println("Check if you are using the right config file. You can use a --config directive to specify one.")
return nil return nil
@ -131,7 +128,7 @@ func runRecreateTable(_ context.Context, cmd *cli.Command) error {
} }
recreateTables := migrate_base.RecreateTables(beans...) 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 { if err := migrations.EnsureUpToDate(ctx, x); err != nil {
return err return err
} }
@ -161,10 +158,7 @@ func setupDoctorDefaultLogger(cmd *cli.Command, colorize bool) {
} }
} }
func runDoctorCheck(_ context.Context, cmd *cli.Command) error { func runDoctorCheck(ctx context.Context, cmd *cli.Command) error {
stdCtx, cancel := installSignals()
defer cancel()
colorize := log.CanColorStdout colorize := log.CanColorStdout
if cmd.IsSet("color") { if cmd.IsSet("color") {
colorize = cmd.Bool("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)
} }

View File

@ -22,11 +22,8 @@ var cmdDoctorConvert = &cli.Command{
Action: runDoctorConvert, Action: runDoctorConvert,
} }
func runDoctorConvert(_ context.Context, cmd *cli.Command) error { func runDoctorConvert(ctx context.Context, cmd *cli.Command) error {
stdCtx, cancel := installSignals() if err := initDB(ctx); err != nil {
defer cancel()
if err := initDB(stdCtx); err != nil {
return err return err
} }

View File

@ -102,7 +102,7 @@ func fatal(format string, args ...any) {
log.Fatal(format, args...) log.Fatal(format, args...)
} }
func runDump(_ context.Context, cmd *cli.Command) error { func runDump(ctx context.Context, cmd *cli.Command) error {
setting.MustInstalled() setting.MustInstalled()
quite := cmd.Bool("quiet") quite := cmd.Bool("quiet")
@ -137,10 +137,7 @@ func runDump(_ context.Context, cmd *cli.Command) error {
setting.DisableLoggerInit() setting.DisableLoggerInit()
setting.LoadSettings() // cannot access session settings otherwise setting.LoadSettings() // cannot access session settings otherwise
stdCtx, cancel := installSignals() err := db.InitEngine(ctx)
defer cancel()
err := db.InitEngine(stdCtx)
if err != nil { if err != nil {
return err return err
} }

View File

@ -79,11 +79,8 @@ wiki, issues, labels, releases, release_assets, milestones, pull_requests, comme
}, },
} }
func runDumpRepository(_ context.Context, cmd *cli.Command) error { func runDumpRepository(ctx context.Context, cmd *cli.Command) error {
stdCtx, cancel := installSignals() if err := initDB(ctx); err != nil {
defer cancel()
if err := initDB(stdCtx); err != nil {
return err return err
} }

View File

@ -161,12 +161,10 @@ func (n *nilWriter) WriteString(s string) (int, error) {
return len(s), nil 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 { if isInternal, _ := strconv.ParseBool(os.Getenv(repo_module.EnvIsInternal)); isInternal {
return nil return nil
} }
ctx, cancel := installSignals()
defer cancel()
setup(ctx, c.Bool("debug")) setup(ctx, c.Bool("debug"))
@ -309,10 +307,7 @@ func runHookUpdate(_ context.Context, c *cli.Command) error {
return nil return nil
} }
func runHookPostReceive(_ context.Context, c *cli.Command) error { func runHookPostReceive(ctx context.Context, c *cli.Command) error {
ctx, cancel := installSignals()
defer cancel()
setup(ctx, c.Bool("debug")) setup(ctx, c.Bool("debug"))
// First of all run update-server-info no matter what // First of all run update-server-info no matter what
@ -496,10 +491,7 @@ func pushOptions() map[string]string {
return opts return opts
} }
func runHookProcReceive(_ context.Context, c *cli.Command) error { func runHookProcReceive(ctx context.Context, c *cli.Command) error {
ctx, cancel := installSignals()
defer cancel()
setup(ctx, c.Bool("debug")) setup(ctx, c.Bool("debug"))
if len(os.Getenv("SSH_ORIGINAL_COMMAND")) == 0 { if len(os.Getenv("SSH_ORIGINAL_COMMAND")) == 0 {

View File

@ -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") { if !c.IsSet("username") {
return errors.New("No username provided") 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") return errors.New("No key type and content provided")
} }
ctx, cancel := installSignals()
defer cancel()
setup(ctx, c.Bool("debug")) setup(ctx, c.Bool("debug"))
authorizedString, extra := private.AuthorizedPublicKeyByContent(ctx, content) authorizedString, extra := private.AuthorizedPublicKeyByContent(ctx, content)

View File

@ -13,10 +13,7 @@ import (
"github.com/urfave/cli/v3" "github.com/urfave/cli/v3"
) )
func runSendMail(_ context.Context, c *cli.Command) error { func runSendMail(ctx context.Context, c *cli.Command) error {
ctx, cancel := installSignals()
defer cancel()
setting.MustInstalled() setting.MustInstalled()
if err := argsSet(c, "title"); err != nil { if err := argsSet(c, "title"); err != nil {

View File

@ -173,7 +173,9 @@ func NewMainApp(appVer AppVersion) *cli.Command {
} }
func RunMainApp(app *cli.Command, args ...string) error { 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 { if err == nil {
return nil return nil
} }

View File

@ -109,46 +109,31 @@ var (
} }
) )
func runShutdown(_ context.Context, c *cli.Command) error { func runShutdown(ctx context.Context, c *cli.Command) error {
ctx, cancel := installSignals()
defer cancel()
setup(ctx, c.Bool("debug")) setup(ctx, c.Bool("debug"))
extra := private.Shutdown(ctx) extra := private.Shutdown(ctx)
return handleCliResponseExtra(extra) return handleCliResponseExtra(extra)
} }
func runRestart(_ context.Context, c *cli.Command) error { func runRestart(ctx context.Context, c *cli.Command) error {
ctx, cancel := installSignals()
defer cancel()
setup(ctx, c.Bool("debug")) setup(ctx, c.Bool("debug"))
extra := private.Restart(ctx) extra := private.Restart(ctx)
return handleCliResponseExtra(extra) return handleCliResponseExtra(extra)
} }
func runReloadTemplates(_ context.Context, c *cli.Command) error { func runReloadTemplates(ctx context.Context, c *cli.Command) error {
ctx, cancel := installSignals()
defer cancel()
setup(ctx, c.Bool("debug")) setup(ctx, c.Bool("debug"))
extra := private.ReloadTemplates(ctx) extra := private.ReloadTemplates(ctx)
return handleCliResponseExtra(extra) return handleCliResponseExtra(extra)
} }
func runFlushQueues(_ context.Context, c *cli.Command) error { func runFlushQueues(ctx context.Context, c *cli.Command) error {
ctx, cancel := installSignals()
defer cancel()
setup(ctx, c.Bool("debug")) setup(ctx, c.Bool("debug"))
extra := private.FlushQueues(ctx, c.Duration("timeout"), c.Bool("non-blocking")) extra := private.FlushQueues(ctx, c.Duration("timeout"), c.Bool("non-blocking"))
return handleCliResponseExtra(extra) return handleCliResponseExtra(extra)
} }
func runProcesses(_ context.Context, c *cli.Command) error { func runProcesses(ctx context.Context, c *cli.Command) error {
ctx, cancel := installSignals()
defer cancel()
setup(ctx, c.Bool("debug")) 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")) 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) return handleCliResponseExtra(extra)

View File

@ -196,10 +196,7 @@ var (
} }
) )
func runRemoveLogger(_ context.Context, c *cli.Command) error { func runRemoveLogger(ctx context.Context, c *cli.Command) error {
ctx, cancel := installSignals()
defer cancel()
setup(ctx, c.Bool("debug")) setup(ctx, c.Bool("debug"))
logger := c.String("logger") logger := c.String("logger")
if len(logger) == 0 { if len(logger) == 0 {
@ -211,10 +208,7 @@ func runRemoveLogger(_ context.Context, c *cli.Command) error {
return handleCliResponseExtra(extra) return handleCliResponseExtra(extra)
} }
func runAddConnLogger(_ context.Context, c *cli.Command) error { func runAddConnLogger(ctx context.Context, c *cli.Command) error {
ctx, cancel := installSignals()
defer cancel()
setup(ctx, c.Bool("debug")) setup(ctx, c.Bool("debug"))
vals := map[string]any{} vals := map[string]any{}
mode := "conn" mode := "conn"
@ -238,13 +232,10 @@ func runAddConnLogger(_ context.Context, c *cli.Command) error {
if c.IsSet("reconnect-on-message") { if c.IsSet("reconnect-on-message") {
vals["reconnectOnMsg"] = c.Bool("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 { func runAddFileLogger(ctx context.Context, c *cli.Command) error {
ctx, cancel := installSignals()
defer cancel()
setup(ctx, c.Bool("debug")) setup(ctx, c.Bool("debug"))
vals := map[string]any{} vals := map[string]any{}
mode := "file" mode := "file"
@ -271,10 +262,10 @@ func runAddFileLogger(_ context.Context, c *cli.Command) error {
if c.IsSet("compression-level") { if c.IsSet("compression-level") {
vals["compressionLevel"] = c.Int("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 { if len(c.String("level")) > 0 {
vals["level"] = log.LevelFromString(c.String("level")).String() 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") { if c.IsSet("writer") {
writer = c.String("writer") writer = c.String("writer")
} }
ctx, cancel := installSignals()
defer cancel()
extra := private.AddLogger(ctx, logger, writer, mode, vals) extra := private.AddLogger(ctx, logger, writer, mode, vals)
return handleCliResponseExtra(extra) return handleCliResponseExtra(extra)
} }
func runPauseLogging(_ context.Context, c *cli.Command) error { func runPauseLogging(ctx context.Context, c *cli.Command) error {
ctx, cancel := installSignals()
defer cancel()
setup(ctx, c.Bool("debug")) setup(ctx, c.Bool("debug"))
userMsg := private.PauseLogging(ctx) userMsg := private.PauseLogging(ctx)
_, _ = fmt.Fprintln(os.Stdout, userMsg) _, _ = fmt.Fprintln(os.Stdout, userMsg)
return nil return nil
} }
func runResumeLogging(_ context.Context, c *cli.Command) error { func runResumeLogging(ctx context.Context, c *cli.Command) error {
ctx, cancel := installSignals()
defer cancel()
setup(ctx, c.Bool("debug")) setup(ctx, c.Bool("debug"))
userMsg := private.ResumeLogging(ctx) userMsg := private.ResumeLogging(ctx)
_, _ = fmt.Fprintln(os.Stdout, userMsg) _, _ = fmt.Fprintln(os.Stdout, userMsg)
return nil return nil
} }
func runReleaseReopenLogging(_ context.Context, c *cli.Command) error { func runReleaseReopenLogging(ctx context.Context, c *cli.Command) error {
ctx, cancel := installSignals()
defer cancel()
setup(ctx, c.Bool("debug")) setup(ctx, c.Bool("debug"))
userMsg := private.ReleaseReopenLogging(ctx) userMsg := private.ReleaseReopenLogging(ctx)
_, _ = fmt.Fprintln(os.Stdout, userMsg) _, _ = fmt.Fprintln(os.Stdout, userMsg)
return nil return nil
} }
func runSetLogSQL(_ context.Context, c *cli.Command) error { func runSetLogSQL(ctx context.Context, c *cli.Command) error {
ctx, cancel := installSignals()
defer cancel()
setup(ctx, c.Bool("debug")) setup(ctx, c.Bool("debug"))
extra := private.SetLogSQL(ctx, !c.Bool("off")) extra := private.SetLogSQL(ctx, !c.Bool("off"))

View File

@ -22,11 +22,8 @@ var CmdMigrate = &cli.Command{
Action: runMigrate, Action: runMigrate,
} }
func runMigrate(_ context.Context, c *cli.Command) error { func runMigrate(ctx context.Context, c *cli.Command) error {
stdCtx, cancel := installSignals() if err := initDB(ctx); err != nil {
defer cancel()
if err := initDB(stdCtx); err != nil {
return err return err
} }

View File

@ -213,11 +213,8 @@ func migrateActionsArtifacts(ctx context.Context, dstStorage storage.ObjectStora
}) })
} }
func runMigrateStorage(_ context.Context, cmd *cli.Command) error { func runMigrateStorage(ctx context.Context, cmd *cli.Command) error {
stdCtx, cancel := installSignals() if err := initDB(ctx); err != nil {
defer cancel()
if err := initDB(stdCtx); err != nil {
return err return err
} }
@ -248,13 +245,13 @@ func runMigrateStorage(_ context.Context, cmd *cli.Command) error {
return nil return nil
} }
dstStorage, err = storage.NewLocalStorage( dstStorage, err = storage.NewLocalStorage(
stdCtx, ctx,
&setting.Storage{ &setting.Storage{
Path: p, Path: p,
}) })
case string(setting.MinioStorageType): case string(setting.MinioStorageType):
dstStorage, err = storage.NewMinioStorage( dstStorage, err = storage.NewMinioStorage(
stdCtx, ctx,
&setting.Storage{ &setting.Storage{
MinioConfig: setting.MinioStorageConfig{ MinioConfig: setting.MinioStorageConfig{
Endpoint: cmd.String("minio-endpoint"), Endpoint: cmd.String("minio-endpoint"),
@ -271,7 +268,7 @@ func runMigrateStorage(_ context.Context, cmd *cli.Command) error {
}) })
case string(setting.AzureBlobStorageType): case string(setting.AzureBlobStorageType):
dstStorage, err = storage.NewAzureBlobStorage( dstStorage, err = storage.NewAzureBlobStorage(
stdCtx, ctx,
&setting.Storage{ &setting.Storage{
AzureBlobConfig: setting.AzureBlobStorageConfig{ AzureBlobConfig: setting.AzureBlobStorageConfig{
Endpoint: cmd.String("azureblob-endpoint"), Endpoint: cmd.String("azureblob-endpoint"),
@ -301,7 +298,7 @@ func runMigrateStorage(_ context.Context, cmd *cli.Command) error {
tp := strings.ToLower(cmd.String("type")) tp := strings.ToLower(cmd.String("type"))
if m, ok := migratedMethods[tp]; ok { if m, ok := migratedMethods[tp]; ok {
if err := m(stdCtx, dstStorage); err != nil { if err := m(ctx, dstStorage); err != nil {
return err return err
} }
log.Info("%s files have successfully been copied to the new storage.", tp) log.Info("%s files have successfully been copied to the new storage.", tp)

View File

@ -49,10 +49,7 @@ wiki, issues, labels, releases, release_assets, milestones, pull_requests, comme
}, },
} }
func runRestoreRepository(_ context.Context, c *cli.Command) error { func runRestoreRepository(ctx context.Context, c *cli.Command) error {
ctx, cancel := installSignals()
defer cancel()
setting.MustInstalled() setting.MustInstalled()
var units []string var units []string
if s := c.String("units"); s != "" { if s := c.String("units"); s != "" {

View File

@ -152,10 +152,7 @@ func getLFSAuthToken(ctx context.Context, lfsVerb string, results *private.ServC
return "Bearer " + tokenString, nil return "Bearer " + tokenString, nil
} }
func runServ(_ context.Context, c *cli.Command) error { func runServ(ctx context.Context, c *cli.Command) error {
ctx, cancel := installSignals()
defer cancel()
// FIXME: This needs to internationalised // FIXME: This needs to internationalised
setup(ctx, c.Bool("debug")) setup(ctx, c.Bool("debug"))

View File

@ -105,16 +105,14 @@ OPTIONS:
` `
app.Action = runBackport app.Action = runBackport
ctx, cancel := installSignals()
if err := app.Run(context.Background(), os.Args); err != nil { defer cancel()
if err := app.Run(ctx, os.Args); err != nil {
fmt.Fprintf(os.Stderr, "Unable to backport: %v\n", err) fmt.Fprintf(os.Stderr, "Unable to backport: %v\n", err)
} }
} }
func runBackport(_ context.Context, c *cli.Command) error { func runBackport(ctx context.Context, c *cli.Command) error {
ctx, cancel := installSignals()
defer cancel()
continuing := c.Bool("continue") continuing := c.Bool("continue")
var pr string var pr string