Skip to content

Commit ac3cfad

Browse files
zeripathflokli
andauthored
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 <[email protected]> Co-authored-by: Florian Klink <[email protected]>
1 parent ee97e6a commit ac3cfad

File tree

7 files changed

+12
-9
lines changed

7 files changed

+12
-9
lines changed

cmd/web.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ and it takes care of all the other things for you`,
4141
},
4242
cli.StringFlag{
4343
Name: "pid, P",
44-
Value: "/var/run/gitea.pid",
44+
Value: setting.PIDFile,
4545
Usage: "Custom pid file path",
4646
},
4747
},
@@ -110,7 +110,8 @@ func runWeb(ctx *cli.Context) error {
110110

111111
// Set pid file setting
112112
if ctx.IsSet("pid") {
113-
setting.CustomPID = ctx.String("pid")
113+
setting.PIDFile = ctx.String("pid")
114+
setting.WritePIDFile = true
114115
}
115116

116117
// Perform global initialization

contrib/init/debian/gitea

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
1818
DESC="Gitea - Git with a cup of tea"
1919
NAME=gitea
2020
SERVICEVERBOSE=yes
21-
PIDFILE=/var/run/$NAME.pid
21+
PIDFILE=/run/$NAME.pid
2222
SCRIPTNAME=/etc/init.d/$NAME
2323
WORKINGDIR=/var/lib/$NAME
2424
DAEMON=/usr/local/bin/$NAME

contrib/init/gentoo/gitea

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ start_stop_daemon_args="--user ${USER} --chdir ${DIR}"
77
command="/usr/local/bin/gitea"
88
command_args="web -c /etc/gitea/app.ini"
99
command_background=yes
10-
pidfile=/var/run/gitea.pid
10+
pidfile=/run/gitea.pid
1111

1212
depend()
1313
{

contrib/init/suse/gitea

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ case "$1" in
9393

9494
# Return value is slightly different for the status command:
9595
# 0 - service up and running
96-
# 1 - service dead, but /var/run/ pid file exists
96+
# 1 - service dead, but /run/ pid file exists
9797
# 2 - service dead, but /var/lock/ lock file exists
9898
# 3 - service not running (unused)
9999
# 4 - service status unknown :-(

docs/content/doc/installation/from-source.en-us.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ using the `LDFLAGS` environment variable for `make`. The appropriate settings ar
155155
* For `CustomConf` you should use `-X \"code.gitea.io/gitea/modules/setting.CustomConf=conf.ini\"`
156156
* For `AppWorkPath` you should use `-X \"code.gitea.io/gitea/modules/setting.AppWorkPath=working-path\"`
157157
* For `StaticRootPath` you should use `-X \"code.gitea.io/gitea/modules/setting.StaticRootPath=static-root-path\"`
158+
* To change the default PID file location use `-X \"code.gitea.io/gitea/modules/setting.PIDFile=/run/gitea.pid\"`
158159

159160
Add as many of the strings with their preceding `-X` to the `LDFLAGS` variable and run `make build`
160161
with the appropriate `TAGS` as above.

docs/content/doc/usage/command-line.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Starts the server:
4444
- Examples:
4545
- `gitea web`
4646
- `gitea web --port 80`
47-
- `gitea web --config /etc/gitea.ini --pid /var/run/gitea.pid`
47+
- `gitea web --config /etc/gitea.ini --pid /some/custom/gitea.pid`
4848
- Notes:
4949
- Gitea should not be run as root. To bind to a port below 1024, you can use setcap on
5050
Linux: `sudo setcap 'cap_net_bind_service=+ep' /path/to/gitea`. This will need to be

modules/setting/setting.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,8 @@ var (
382382
Cfg *ini.File
383383
CustomPath string // Custom directory path
384384
CustomConf string
385-
CustomPID string
385+
PIDFile = "/var/run/gitea.pid"
386+
WritePIDFile bool
386387
ProdMode bool
387388
RunUser string
388389
IsWindows bool
@@ -535,8 +536,8 @@ func SetCustomPathAndConf(providedCustom, providedConf, providedWorkPath string)
535536
func NewContext() {
536537
Cfg = ini.Empty()
537538

538-
if len(CustomPID) > 0 {
539-
createPIDFile(CustomPID)
539+
if WritePIDFile && len(PIDFile) > 0 {
540+
createPIDFile(PIDFile)
540541
}
541542

542543
if com.IsFile(CustomConf) {

0 commit comments

Comments
 (0)