You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

manager.go 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package cmd
  4. import (
  5. "os"
  6. "time"
  7. "code.gitea.io/gitea/modules/private"
  8. "github.com/urfave/cli"
  9. )
  10. var (
  11. // CmdManager represents the manager command
  12. CmdManager = cli.Command{
  13. Name: "manager",
  14. Usage: "Manage the running gitea process",
  15. Description: "This is a command for managing the running gitea process",
  16. Subcommands: []cli.Command{
  17. subcmdShutdown,
  18. subcmdRestart,
  19. subcmdReloadTemplates,
  20. subcmdFlushQueues,
  21. subcmdLogging,
  22. subCmdProcesses,
  23. },
  24. }
  25. subcmdShutdown = cli.Command{
  26. Name: "shutdown",
  27. Usage: "Gracefully shutdown the running process",
  28. Flags: []cli.Flag{
  29. cli.BoolFlag{
  30. Name: "debug",
  31. },
  32. },
  33. Action: runShutdown,
  34. }
  35. subcmdRestart = cli.Command{
  36. Name: "restart",
  37. Usage: "Gracefully restart the running process - (not implemented for windows servers)",
  38. Flags: []cli.Flag{
  39. cli.BoolFlag{
  40. Name: "debug",
  41. },
  42. },
  43. Action: runRestart,
  44. }
  45. subcmdReloadTemplates = cli.Command{
  46. Name: "reload-templates",
  47. Usage: "Reload template files in the running process",
  48. Flags: []cli.Flag{
  49. cli.BoolFlag{
  50. Name: "debug",
  51. },
  52. },
  53. Action: runReloadTemplates,
  54. }
  55. subcmdFlushQueues = cli.Command{
  56. Name: "flush-queues",
  57. Usage: "Flush queues in the running process",
  58. Action: runFlushQueues,
  59. Flags: []cli.Flag{
  60. cli.DurationFlag{
  61. Name: "timeout",
  62. Value: 60 * time.Second,
  63. Usage: "Timeout for the flushing process",
  64. },
  65. cli.BoolFlag{
  66. Name: "non-blocking",
  67. Usage: "Set to true to not wait for flush to complete before returning",
  68. },
  69. cli.BoolFlag{
  70. Name: "debug",
  71. },
  72. },
  73. }
  74. subCmdProcesses = cli.Command{
  75. Name: "processes",
  76. Usage: "Display running processes within the current process",
  77. Action: runProcesses,
  78. Flags: []cli.Flag{
  79. cli.BoolFlag{
  80. Name: "debug",
  81. },
  82. cli.BoolFlag{
  83. Name: "flat",
  84. Usage: "Show processes as flat table rather than as tree",
  85. },
  86. cli.BoolFlag{
  87. Name: "no-system",
  88. Usage: "Do not show system processes",
  89. },
  90. cli.BoolFlag{
  91. Name: "stacktraces",
  92. Usage: "Show stacktraces",
  93. },
  94. cli.BoolFlag{
  95. Name: "json",
  96. Usage: "Output as json",
  97. },
  98. cli.StringFlag{
  99. Name: "cancel",
  100. Usage: "Process PID to cancel. (Only available for non-system processes.)",
  101. },
  102. },
  103. }
  104. )
  105. func runShutdown(c *cli.Context) error {
  106. ctx, cancel := installSignals()
  107. defer cancel()
  108. setup(ctx, c.Bool("debug"))
  109. extra := private.Shutdown(ctx)
  110. return handleCliResponseExtra(extra)
  111. }
  112. func runRestart(c *cli.Context) error {
  113. ctx, cancel := installSignals()
  114. defer cancel()
  115. setup(ctx, c.Bool("debug"))
  116. extra := private.Restart(ctx)
  117. return handleCliResponseExtra(extra)
  118. }
  119. func runReloadTemplates(c *cli.Context) error {
  120. ctx, cancel := installSignals()
  121. defer cancel()
  122. setup(ctx, c.Bool("debug"))
  123. extra := private.ReloadTemplates(ctx)
  124. return handleCliResponseExtra(extra)
  125. }
  126. func runFlushQueues(c *cli.Context) error {
  127. ctx, cancel := installSignals()
  128. defer cancel()
  129. setup(ctx, c.Bool("debug"))
  130. extra := private.FlushQueues(ctx, c.Duration("timeout"), c.Bool("non-blocking"))
  131. return handleCliResponseExtra(extra)
  132. }
  133. func runProcesses(c *cli.Context) error {
  134. ctx, cancel := installSignals()
  135. defer cancel()
  136. setup(ctx, c.Bool("debug"))
  137. extra := private.Processes(ctx, os.Stdout, c.Bool("flat"), c.Bool("no-system"), c.Bool("stacktraces"), c.Bool("json"), c.String("cancel"))
  138. return handleCliResponseExtra(extra)
  139. }