2020-01-29 06:31:06 +05:30
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/private"
|
|
|
|
|
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// CmdManager represents the manager command
|
|
|
|
CmdManager = cli.Command{
|
|
|
|
Name: "manager",
|
|
|
|
Usage: "Manage the running gitea process",
|
|
|
|
Description: "This is a command for managing the running gitea process",
|
|
|
|
Subcommands: []cli.Command{
|
|
|
|
subcmdShutdown,
|
|
|
|
subcmdRestart,
|
|
|
|
subcmdFlushQueues,
|
2020-07-06 05:37:07 +05:30
|
|
|
subcmdLogging,
|
2022-03-31 22:31:43 +05:30
|
|
|
subCmdProcesses,
|
2020-01-29 06:31:06 +05:30
|
|
|
},
|
|
|
|
}
|
|
|
|
subcmdShutdown = cli.Command{
|
2020-07-06 05:37:07 +05:30
|
|
|
Name: "shutdown",
|
|
|
|
Usage: "Gracefully shutdown the running process",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "debug",
|
|
|
|
},
|
|
|
|
},
|
2020-01-29 06:31:06 +05:30
|
|
|
Action: runShutdown,
|
|
|
|
}
|
|
|
|
subcmdRestart = cli.Command{
|
2020-07-06 05:37:07 +05:30
|
|
|
Name: "restart",
|
|
|
|
Usage: "Gracefully restart the running process - (not implemented for windows servers)",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "debug",
|
|
|
|
},
|
|
|
|
},
|
2020-01-29 06:31:06 +05:30
|
|
|
Action: runRestart,
|
|
|
|
}
|
|
|
|
subcmdFlushQueues = cli.Command{
|
|
|
|
Name: "flush-queues",
|
|
|
|
Usage: "Flush queues in the running process",
|
|
|
|
Action: runFlushQueues,
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.DurationFlag{
|
|
|
|
Name: "timeout",
|
|
|
|
Value: 60 * time.Second,
|
|
|
|
Usage: "Timeout for the flushing process",
|
2022-01-20 23:16:10 +05:30
|
|
|
},
|
|
|
|
cli.BoolFlag{
|
2020-01-29 06:31:06 +05:30
|
|
|
Name: "non-blocking",
|
|
|
|
Usage: "Set to true to not wait for flush to complete before returning",
|
|
|
|
},
|
2020-07-06 05:37:07 +05:30
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "debug",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2022-03-31 22:31:43 +05:30
|
|
|
subCmdProcesses = cli.Command{
|
|
|
|
Name: "processes",
|
|
|
|
Usage: "Display running processes within the current process",
|
|
|
|
Action: runProcesses,
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "debug",
|
|
|
|
},
|
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "flat",
|
|
|
|
Usage: "Show processes as flat table rather than as tree",
|
|
|
|
},
|
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "no-system",
|
Fix various typos (#20338)
* Fix various typos
Found via `codespell -q 3 -S ./options/locale,./options/license,./public/vendor -L actived,allways,attachements,ba,befores,commiter,pullrequest,pullrequests,readby,splitted,te,unknwon`
Co-authored-by: zeripath <art27@cantab.net>
2022-07-13 03:02:37 +05:30
|
|
|
Usage: "Do not show system processes",
|
2022-03-31 22:31:43 +05:30
|
|
|
},
|
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "stacktraces",
|
|
|
|
Usage: "Show stacktraces",
|
|
|
|
},
|
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "json",
|
|
|
|
Usage: "Output as json",
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "cancel",
|
|
|
|
Usage: "Process PID to cancel. (Only available for non-system processes.)",
|
2020-07-06 05:37:07 +05:30
|
|
|
},
|
2020-01-29 06:31:06 +05:30
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func runShutdown(c *cli.Context) error {
|
2021-07-14 20:13:13 +05:30
|
|
|
ctx, cancel := installSignals()
|
|
|
|
defer cancel()
|
|
|
|
|
2020-07-06 05:37:07 +05:30
|
|
|
setup("manager", c.Bool("debug"))
|
2021-07-14 20:13:13 +05:30
|
|
|
statusCode, msg := private.Shutdown(ctx)
|
2020-01-29 06:31:06 +05:30
|
|
|
switch statusCode {
|
|
|
|
case http.StatusInternalServerError:
|
2021-07-14 20:13:13 +05:30
|
|
|
return fail("InternalServerError", msg)
|
2020-01-29 06:31:06 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintln(os.Stdout, msg)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func runRestart(c *cli.Context) error {
|
2021-07-14 20:13:13 +05:30
|
|
|
ctx, cancel := installSignals()
|
|
|
|
defer cancel()
|
|
|
|
|
2020-07-06 05:37:07 +05:30
|
|
|
setup("manager", c.Bool("debug"))
|
2021-07-14 20:13:13 +05:30
|
|
|
statusCode, msg := private.Restart(ctx)
|
2020-01-29 06:31:06 +05:30
|
|
|
switch statusCode {
|
|
|
|
case http.StatusInternalServerError:
|
2021-07-14 20:13:13 +05:30
|
|
|
return fail("InternalServerError", msg)
|
2020-01-29 06:31:06 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintln(os.Stdout, msg)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func runFlushQueues(c *cli.Context) error {
|
2021-07-14 20:13:13 +05:30
|
|
|
ctx, cancel := installSignals()
|
|
|
|
defer cancel()
|
|
|
|
|
2020-07-06 05:37:07 +05:30
|
|
|
setup("manager", c.Bool("debug"))
|
2021-07-14 20:13:13 +05:30
|
|
|
statusCode, msg := private.FlushQueues(ctx, c.Duration("timeout"), c.Bool("non-blocking"))
|
2020-01-29 06:31:06 +05:30
|
|
|
switch statusCode {
|
|
|
|
case http.StatusInternalServerError:
|
2021-07-14 20:13:13 +05:30
|
|
|
return fail("InternalServerError", msg)
|
2020-01-29 06:31:06 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintln(os.Stdout, msg)
|
|
|
|
return nil
|
|
|
|
}
|
2020-07-06 05:37:07 +05:30
|
|
|
|
2022-03-31 22:31:43 +05:30
|
|
|
func runProcesses(c *cli.Context) error {
|
2021-07-14 20:13:13 +05:30
|
|
|
ctx, cancel := installSignals()
|
|
|
|
defer cancel()
|
|
|
|
|
2020-07-06 05:37:07 +05:30
|
|
|
setup("manager", c.Bool("debug"))
|
2022-03-31 22:31:43 +05:30
|
|
|
statusCode, msg := private.Processes(ctx, os.Stdout, c.Bool("flat"), c.Bool("no-system"), c.Bool("stacktraces"), c.Bool("json"), c.String("cancel"))
|
2020-07-06 05:37:07 +05:30
|
|
|
switch statusCode {
|
|
|
|
case http.StatusInternalServerError:
|
2021-07-14 20:13:13 +05:30
|
|
|
return fail("InternalServerError", msg)
|
2020-07-06 05:37:07 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|