Skip to content

Fix --port setting #13288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions cmd/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ and it takes care of all the other things for you`,
Value: "3000",
Usage: "Temporary port number to prevent conflict",
},
cli.StringFlag{
Name: "install-port",
Value: "3000",
Usage: "Temporary port number to run the install page on to prevent conflict",
},
cli.StringFlag{
Name: "pid, P",
Value: setting.PIDFile,
Expand Down Expand Up @@ -116,16 +121,20 @@ func runWeb(ctx *cli.Context) error {
setting.WritePIDFile = true
}

// Flag for port number in case first time run conflict.
if ctx.IsSet("port") {
if err := setPort(ctx.String("port")); err != nil {
return err
}
}

// Perform pre-initialization
needsInstall := routers.PreInstallInit(graceful.GetManager().HammerContext())
if needsInstall {
// Flag for port number in case first time run conflict
if ctx.IsSet("port") {
if err := setPort(ctx.String("port")); err != nil {
return err
}
}
if ctx.IsSet("install-port") {
if err := setPort(ctx.String("install-port")); err != nil {
return err
}
}
m := routes.NewMacaron()
routes.RegisterInstallRoute(m)
err := listen(m, false)
Expand All @@ -152,6 +161,12 @@ func runWeb(ctx *cli.Context) error {
// Perform global initialization
routers.GlobalInit(graceful.GetManager().HammerContext())

// Override the provided port number within the configuration
if ctx.IsSet("port") {
if err := setPort(ctx.String("port")); err != nil {
return err
}
}
// Set up Macaron
m := routes.NewMacaron()
routes.RegisterRoutes(m)
Expand Down Expand Up @@ -190,10 +205,6 @@ func setPort(port string) error {
defaultLocalURL += ":" + setting.HTTPPort + "/"

cfg.Section("server").Key("LOCAL_ROOT_URL").SetValue(defaultLocalURL)

if err := cfg.SaveTo(setting.CustomConf); err != nil {
return fmt.Errorf("Error saving generated JWT Secret to custom config: %v", err)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--port states that it is temporary so it shouldn't write to the ini...

however, this is going to break gitea serv, admin, manager etc. I just don't know what to do here.

In terms of doing a pure bugfix for the linked Issue only this change should be dropped but it's really hard to know what to do here.

}
return nil
}
Expand Down
1 change: 1 addition & 0 deletions docs/content/doc/usage/command-line.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Starts the server:

- Options:
- `--port number`, `-p number`: Port number. Optional. (default: 3000). Overrides configuration file.
- `--install-port number`: Port number to run the install page on. Optional. (default: 3000). Overrides configuration file.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change could be another PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's part of the fix really.

If you make --port apply both before the install page and after the install page then the PORT option in the install page is irrelevant and it is overwritten.

If you make --port only apply once then if there is a graceful restart after install the port that gitea runs on will change.

If you make --port only apply to the install page then that may change behaviour for other people.

In this case the only solution is provide a separate option for the install page then you can have a consistent solution.

- `--pid path`, `-P path`: Pidfile path. Optional.
- Examples:
- `gitea web`
Expand Down