CurrentUsername is not always reliable #676

Closed
opened 2025-11-02 03:32:57 -06:00 by GiteaMirror · 2 comments
Owner

Originally created by @IzzySoft on GitHub (Apr 28, 2017).

  • Gitea version (or commit ref): 1.1.0
  • Git version: 2.1.4
  • Operating system: Bananian (based on Debian Jessie)
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist:

Description

This is an issue existing with Gogs as well (but not considered an issue by Unknwon):

When starting Gitea via e.g. init.d using start-stop-daemon (defining the correct user/group), I get the following error:

[...s/setting/setting.go:801 NewContext()] [E] Expect user 'git' but current user is: root

Took me a while to figure (and only the linked Gogs issue brought me on the right path): the environment variable $USER still points to root, though id -un as well as whoami indicate the script is running under the correct user (i.e. git:git). I've worked around that using a shell script, prefixing the gitea web command by a line stating USER=$(id -un) – but shouldn't Gitea figure that itself? Some other users might give up before figuring :)

And while on it: is there a way to tell Gitea it should run in "daemon mode" instead of "in foreground" – other than using &?

Originally created by @IzzySoft on GitHub (Apr 28, 2017). - Gitea version (or commit ref): 1.1.0 - Git version: 2.1.4 - Operating system: Bananian (based on Debian Jessie) - Database (use `[x]`): - [ ] PostgreSQL - [ ] MySQL - [ ] MSSQL - [x] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [ ] No - [x] Not relevant - Log gist: ## Description This is an issue [existing with Gogs as well](https://github.com/gogits/gogs/issues/3948) (but not considered an issue by Unknwon): When starting *Gitea* via e.g. `init.d` using `start-stop-daemon` (defining the correct user/group), I get the following error: [...s/setting/setting.go:801 NewContext()] [E] Expect user 'git' but current user is: root Took me a while to figure (and only the linked Gogs issue brought me on the right path): the environment variable `$USER` still points to `root`, though `id -un` as well as `whoami` indicate the script is running under the correct user (i.e. `git:git`). I've worked around that using a shell script, prefixing the `gitea web` command by a line stating `USER=$(id -un)` – but shouldn't Gitea figure that itself? Some other users might give up before figuring :) And while on it: is there a way to tell Gitea it should run in "daemon mode" instead of "in foreground" – other than using `&`?
GiteaMirror added the type/question label 2025-11-02 03:32:57 -06:00
Author
Owner

@bkcsoft commented on GitHub (Apr 28, 2017):

I would say that this is a bug in start-stop-daemon, not gitea :trollface:

@bkcsoft commented on GitHub (Apr 28, 2017): I would say that this is a bug in `start-stop-daemon`, not gitea :trollface:
Author
Owner

@IzzySoft commented on GitHub (Apr 29, 2017):

One could see it that way, sure. But where are the chances better that it gets fixed? 😜

Btw, I just figured how Unknwon worked around that. The Gogs repo contains an init.d script which, with some minor adjustments, could be used for Gitea as well. And guess how it's achieved there? See e.g. lines 27 + 51:

USER=git
…
sh -c "USER=$USER start-stop-daemon …  --chuid $USER …

As it would solve the underlying issue, may I suggest to "pull" that script, make the 3 minor adjustments (variables NAME, DESC, WORKINGDIR), add it to the corresponding directory in the Gitea repo, and have a pointer to it from the documentation (a la "if you want to run it automatically at system start on your Linux system, you can use that init.d script")?

@IzzySoft commented on GitHub (Apr 29, 2017): One could see it that way, sure. But where are the chances better that it gets fixed? :stuck_out_tongue_winking_eye: Btw, I just figured how Unknwon worked around that. The Gogs repo contains an [init.d script](https://github.com/gogits/gogs/blob/master/scripts/init/debian/gogs) which, with some minor adjustments, could be used for Gitea as well. And guess how it's achieved there? See e.g. lines 27 + 51: USER=git … sh -c "USER=$USER start-stop-daemon … --chuid $USER … As it would solve the underlying issue, may I suggest to "pull" that script, make the 3 minor adjustments (variables `NAME`, `DESC`, `WORKINGDIR`), add it to the corresponding directory in the Gitea repo, and have a pointer to it from the documentation (a la "if you want to run it automatically at system start on your Linux system, you can use that init.d script")?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#676