diff --git a/cmd/web.go b/cmd/web.go index 6efadb9419..f0e1b16e7f 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -41,7 +41,7 @@ and it takes care of all the other things for you`, }, cli.StringFlag{ Name: "pid, P", - Value: "/var/run/gitea.pid", + Value: setting.PIDFile, Usage: "Custom pid file path", }, }, @@ -110,7 +110,8 @@ func runWeb(ctx *cli.Context) error { // Set pid file setting if ctx.IsSet("pid") { - setting.CustomPID = ctx.String("pid") + setting.PIDFile = ctx.String("pid") + setting.WritePIDFile = true } // Perform global initialization diff --git a/contrib/init/debian/gitea b/contrib/init/debian/gitea index b7911f106e..2246309440 100644 --- a/contrib/init/debian/gitea +++ b/contrib/init/debian/gitea @@ -18,7 +18,7 @@ PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin DESC="Gitea - Git with a cup of tea" NAME=gitea SERVICEVERBOSE=yes -PIDFILE=/var/run/$NAME.pid +PIDFILE=/run/$NAME.pid SCRIPTNAME=/etc/init.d/$NAME WORKINGDIR=/var/lib/$NAME DAEMON=/usr/local/bin/$NAME diff --git a/contrib/init/gentoo/gitea b/contrib/init/gentoo/gitea index c40fc93f5f..e423eae54d 100644 --- a/contrib/init/gentoo/gitea +++ b/contrib/init/gentoo/gitea @@ -7,7 +7,7 @@ start_stop_daemon_args="--user ${USER} --chdir ${DIR}" command="/usr/local/bin/gitea" command_args="web -c /etc/gitea/app.ini" command_background=yes -pidfile=/var/run/gitea.pid +pidfile=/run/gitea.pid depend() { diff --git a/contrib/init/suse/gitea b/contrib/init/suse/gitea index 23178583ff..6391bedaf8 100644 --- a/contrib/init/suse/gitea +++ b/contrib/init/suse/gitea @@ -93,7 +93,7 @@ case "$1" in # Return value is slightly different for the status command: # 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 # 3 - service not running (unused) # 4 - service status unknown :-( diff --git a/docs/content/doc/installation/from-source.en-us.md b/docs/content/doc/installation/from-source.en-us.md index 9c7016577f..ef116afc5a 100644 --- a/docs/content/doc/installation/from-source.en-us.md +++ b/docs/content/doc/installation/from-source.en-us.md @@ -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 `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\"` +* 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` with the appropriate `TAGS` as above. diff --git a/docs/content/doc/usage/command-line.en-us.md b/docs/content/doc/usage/command-line.en-us.md index 3715be7cbd..e458b11ba4 100644 --- a/docs/content/doc/usage/command-line.en-us.md +++ b/docs/content/doc/usage/command-line.en-us.md @@ -44,7 +44,7 @@ Starts the server: - Examples: - `gitea web` - `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: - 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 diff --git a/modules/setting/setting.go b/modules/setting/setting.go index d4ce13079a..d77df2d75f 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -382,7 +382,8 @@ var ( Cfg *ini.File CustomPath string // Custom directory path CustomConf string - CustomPID string + PIDFile = "/var/run/gitea.pid" + WritePIDFile bool ProdMode bool RunUser string IsWindows bool @@ -535,8 +536,8 @@ func SetCustomPathAndConf(providedCustom, providedConf, providedWorkPath string) func NewContext() { Cfg = ini.Empty() - if len(CustomPID) > 0 { - createPIDFile(CustomPID) + if WritePIDFile && len(PIDFile) > 0 { + createPIDFile(PIDFile) } if com.IsFile(CustomConf) {