You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by ju...@apache.org on 2021/06/24 15:07:33 UTC
[apisix-dashboard] branch master updated: feat: additional flag to
force start manager-api (#1898)
This is an automated email from the ASF dual-hosted git repository.
juzhiyuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-dashboard.git
The following commit(s) were added to refs/heads/master by this push:
new 4612d02 feat: additional flag to force start manager-api (#1898)
4612d02 is described below
commit 4612d02a9c8e50abf13836e4f66ea56e1ab2e145
Author: Bisakh Mondal <bi...@gmail.com>
AuthorDate: Thu Jun 24 20:37:25 2021 +0530
feat: additional flag to force start manager-api (#1898)
---
api/cmd/root.go | 4 +++-
api/internal/utils/pid.go | 9 ++++++---
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/api/cmd/root.go b/api/cmd/root.go
index cee9029..05e16a2 100644
--- a/api/cmd/root.go
+++ b/api/cmd/root.go
@@ -43,6 +43,7 @@ import (
var (
configFile string
+ forceStart bool
)
var rootCmd = &cobra.Command{
@@ -65,6 +66,7 @@ func init() {
rootCmd.PersistentFlags().StringVarP(&configFile, "config", "c", "./conf/conf.yml", "config file")
rootCmd.PersistentFlags().StringVarP(&conf.WorkDir, "work-dir", "p", ".", "current work directory")
+ rootCmd.PersistentFlags().BoolVarP(&forceStart, "force", "f", false, "force start manager-api")
rootCmd.AddCommand(
newVersionCommand(),
@@ -86,7 +88,7 @@ func manageAPI() error {
conf.InitConf()
log.InitLogger()
- if err := utils.WritePID(conf.PIDPath); err != nil {
+ if err := utils.WritePID(conf.PIDPath, forceStart); err != nil {
log.Errorf("failed to write pid: %s", err)
return err
}
diff --git a/api/internal/utils/pid.go b/api/internal/utils/pid.go
index 4080a53..4827588 100644
--- a/api/internal/utils/pid.go
+++ b/api/internal/utils/pid.go
@@ -25,9 +25,12 @@ import (
)
// WritePID write pid to the given file path.
-func WritePID(filepath string) error {
- if _, err := os.Stat(filepath); err == nil {
- return fmt.Errorf("instance of Manager API already running: a pid file exists in %s", filepath)
+func WritePID(filepath string, forceStart bool) error {
+ if pid, err := ReadPID(filepath); err == nil {
+ if !forceStart {
+ return fmt.Errorf("Instance of Manager API maybe running with a pid %d. If not, please run Manager API with '-f' or '--force' flag\n", pid)
+ }
+ fmt.Printf("Force starting new instance. Another instance of Manager API maybe running with pid %d\n", pid)
}
pid := os.Getpid()
f, err := os.OpenFile(filepath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC|os.O_CREATE, 0600)