Files

155 lines
3.5 KiB
Go
Raw Permalink Normal View History

// Copyright 2020 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package cmd
import (
2025-06-10 14:35:12 +02:00
"context"
"os"
"time"
"code.gitea.io/gitea/modules/private"
2025-06-10 14:35:12 +02:00
"github.com/urfave/cli/v3"
)
func newManagerCommand() *cli.Command {
return &cli.Command{
Name: "manager",
Usage: "Manage the running gitea process",
Description: "This is a command for managing the running gitea process",
2025-06-10 14:35:12 +02:00
Commands: []*cli.Command{
newShutdownCommand(),
newRestartCommand(),
newReloadTemplatesCommand(),
newFlushQueuesCommand(),
newLoggingCommand(),
newProcessesCommand(),
},
}
}
func newShutdownCommand() *cli.Command {
return &cli.Command{
Name: "shutdown",
Usage: "Gracefully shutdown the running process",
Flags: []cli.Flag{
2023-07-21 17:28:19 +08:00
&cli.BoolFlag{
Name: "debug",
},
},
Action: runShutdown,
}
}
func newRestartCommand() *cli.Command {
return &cli.Command{
Name: "restart",
Usage: "Gracefully restart the running process - (not implemented for windows servers)",
Flags: []cli.Flag{
2023-07-21 17:28:19 +08:00
&cli.BoolFlag{
Name: "debug",
},
},
Action: runRestart,
}
}
func newReloadTemplatesCommand() *cli.Command {
return &cli.Command{
Name: "reload-templates",
Usage: "Reload template files in the running process",
Flags: []cli.Flag{
2023-07-21 17:28:19 +08:00
&cli.BoolFlag{
Name: "debug",
},
},
Action: runReloadTemplates,
}
}
func newFlushQueuesCommand() *cli.Command {
return &cli.Command{
Name: "flush-queues",
Usage: "Flush queues in the running process",
Action: runFlushQueues,
Flags: []cli.Flag{
2023-07-21 17:28:19 +08:00
&cli.DurationFlag{
Name: "timeout",
Value: 60 * time.Second,
Usage: "Timeout for the flushing process",
2022-01-20 18:46:10 +01:00
},
2023-07-21 17:28:19 +08:00
&cli.BoolFlag{
Name: "non-blocking",
Usage: "Set to true to not wait for flush to complete before returning",
},
2023-07-21 17:28:19 +08:00
&cli.BoolFlag{
Name: "debug",
},
},
}
}
func newProcessesCommand() *cli.Command {
return &cli.Command{
Name: "processes",
Usage: "Display running processes within the current process",
Action: runProcesses,
Flags: []cli.Flag{
2023-07-21 17:28:19 +08:00
&cli.BoolFlag{
Name: "debug",
},
2023-07-21 17:28:19 +08:00
&cli.BoolFlag{
Name: "flat",
Usage: "Show processes as flat table rather than as tree",
},
2023-07-21 17:28:19 +08:00
&cli.BoolFlag{
Name: "no-system",
2022-07-12 17:32:37 -04:00
Usage: "Do not show system processes",
},
2023-07-21 17:28:19 +08:00
&cli.BoolFlag{
Name: "stacktraces",
Usage: "Show stacktraces",
},
2023-07-21 17:28:19 +08:00
&cli.BoolFlag{
Name: "json",
Usage: "Output as json",
},
2023-07-21 17:28:19 +08:00
&cli.StringFlag{
Name: "cancel",
Usage: "Process PID to cancel. (Only available for non-system processes.)",
},
},
}
}
2025-06-10 14:35:12 +02:00
func runShutdown(ctx context.Context, c *cli.Command) error {
setup(ctx, c.Bool("debug"))
extra := private.Shutdown(ctx)
return handleCliResponseExtra(extra)
}
2025-06-10 14:35:12 +02:00
func runRestart(ctx context.Context, c *cli.Command) error {
setup(ctx, c.Bool("debug"))
extra := private.Restart(ctx)
return handleCliResponseExtra(extra)
}
2025-06-10 14:35:12 +02:00
func runReloadTemplates(ctx context.Context, c *cli.Command) error {
setup(ctx, c.Bool("debug"))
extra := private.ReloadTemplates(ctx)
return handleCliResponseExtra(extra)
}
2025-06-10 14:35:12 +02:00
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)
}
2025-06-10 14:35:12 +02:00
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)
}