Make the default PID file compile-time settable (#12485)

#12391 offered to change the default PID file from /var/run/gitea.pid however in discussion it was decided that this could break users of older systems. An alternative was offered that we could make the PID file compile/link time settable.

This PR does this, and changes the name of the setting from CustomPID to simply PIDFile. It also updates the from-source docs to show how to change the compiler settings to do this.

Closes #12391

Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: Florian Klink <flokli@flokli.de>
This commit is contained in:
zeripath 2020-08-15 21:15:27 +01:00 committed by GitHub
parent ee97e6a66a
commit ac3cfad23d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 12 additions and 9 deletions

View File

@ -41,7 +41,7 @@ and it takes care of all the other things for you`,
}, },
cli.StringFlag{ cli.StringFlag{
Name: "pid, P", Name: "pid, P",
Value: "/var/run/gitea.pid", Value: setting.PIDFile,
Usage: "Custom pid file path", Usage: "Custom pid file path",
}, },
}, },
@ -110,7 +110,8 @@ func runWeb(ctx *cli.Context) error {
// Set pid file setting // Set pid file setting
if ctx.IsSet("pid") { if ctx.IsSet("pid") {
setting.CustomPID = ctx.String("pid") setting.PIDFile = ctx.String("pid")
setting.WritePIDFile = true
} }
// Perform global initialization // Perform global initialization

View File

@ -18,7 +18,7 @@ PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
DESC="Gitea - Git with a cup of tea" DESC="Gitea - Git with a cup of tea"
NAME=gitea NAME=gitea
SERVICEVERBOSE=yes SERVICEVERBOSE=yes
PIDFILE=/var/run/$NAME.pid PIDFILE=/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME SCRIPTNAME=/etc/init.d/$NAME
WORKINGDIR=/var/lib/$NAME WORKINGDIR=/var/lib/$NAME
DAEMON=/usr/local/bin/$NAME DAEMON=/usr/local/bin/$NAME

View File

@ -7,7 +7,7 @@ start_stop_daemon_args="--user ${USER} --chdir ${DIR}"
command="/usr/local/bin/gitea" command="/usr/local/bin/gitea"
command_args="web -c /etc/gitea/app.ini" command_args="web -c /etc/gitea/app.ini"
command_background=yes command_background=yes
pidfile=/var/run/gitea.pid pidfile=/run/gitea.pid
depend() depend()
{ {

View File

@ -93,7 +93,7 @@ case "$1" in
# Return value is slightly different for the status command: # Return value is slightly different for the status command:
# 0 - service up and running # 0 - service up and running
# 1 - service dead, but /var/run/ pid file exists # 1 - service dead, but /run/ pid file exists
# 2 - service dead, but /var/lock/ lock file exists # 2 - service dead, but /var/lock/ lock file exists
# 3 - service not running (unused) # 3 - service not running (unused)
# 4 - service status unknown :-( # 4 - service status unknown :-(

View File

@ -155,6 +155,7 @@ using the `LDFLAGS` environment variable for `make`. The appropriate settings ar
* For `CustomConf` you should use `-X \"code.gitea.io/gitea/modules/setting.CustomConf=conf.ini\"` * For `CustomConf` you should use `-X \"code.gitea.io/gitea/modules/setting.CustomConf=conf.ini\"`
* For `AppWorkPath` you should use `-X \"code.gitea.io/gitea/modules/setting.AppWorkPath=working-path\"` * For `AppWorkPath` you should use `-X \"code.gitea.io/gitea/modules/setting.AppWorkPath=working-path\"`
* For `StaticRootPath` you should use `-X \"code.gitea.io/gitea/modules/setting.StaticRootPath=static-root-path\"` * For `StaticRootPath` you should use `-X \"code.gitea.io/gitea/modules/setting.StaticRootPath=static-root-path\"`
* To change the default PID file location use `-X \"code.gitea.io/gitea/modules/setting.PIDFile=/run/gitea.pid\"`
Add as many of the strings with their preceding `-X` to the `LDFLAGS` variable and run `make build` Add as many of the strings with their preceding `-X` to the `LDFLAGS` variable and run `make build`
with the appropriate `TAGS` as above. with the appropriate `TAGS` as above.

View File

@ -44,7 +44,7 @@ Starts the server:
- Examples: - Examples:
- `gitea web` - `gitea web`
- `gitea web --port 80` - `gitea web --port 80`
- `gitea web --config /etc/gitea.ini --pid /var/run/gitea.pid` - `gitea web --config /etc/gitea.ini --pid /some/custom/gitea.pid`
- Notes: - Notes:
- Gitea should not be run as root. To bind to a port below 1024, you can use setcap on - Gitea should not be run as root. To bind to a port below 1024, you can use setcap on
Linux: `sudo setcap 'cap_net_bind_service=+ep' /path/to/gitea`. This will need to be Linux: `sudo setcap 'cap_net_bind_service=+ep' /path/to/gitea`. This will need to be

View File

@ -382,7 +382,8 @@ var (
Cfg *ini.File Cfg *ini.File
CustomPath string // Custom directory path CustomPath string // Custom directory path
CustomConf string CustomConf string
CustomPID string PIDFile = "/var/run/gitea.pid"
WritePIDFile bool
ProdMode bool ProdMode bool
RunUser string RunUser string
IsWindows bool IsWindows bool
@ -535,8 +536,8 @@ func SetCustomPathAndConf(providedCustom, providedConf, providedWorkPath string)
func NewContext() { func NewContext() {
Cfg = ini.Empty() Cfg = ini.Empty()
if len(CustomPID) > 0 { if WritePIDFile && len(PIDFile) > 0 {
createPIDFile(CustomPID) createPIDFile(PIDFile)
} }
if com.IsFile(CustomConf) { if com.IsFile(CustomConf) {