-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Gitea's path system quirk and bug #24222
Comments
I was able to solve this issue by just adding the proper backupopts:
|
It's difficult to come up with a reasonable way to improve what's going on without understanding why things are the way they are. I've said this before, but for the sake of completeness I'll say it again. Gitea was initially intended to be run from the directory it was built in or a directory similar to it and NOT from /usr/bin/gitea. It would use the directory of its binary as the basis for where it would look for its assets and where it would create its data. Over time, options and configuration were added to allow this directories to be changed from these defaults but ... fundamentally the paths are all built up in a hierarchical fashion from the work-path - that is, the absolute path of the Gitea binary. Now... changing that is difficult without causing lots of breakage.
We have been bodging 3 for a while by providing the script to wrap Gitea in a filesystem hierarchy compliant way and we can compile Gitea with paths in-built to avoid having dependencies on the work-path. Our Dockers finally wrap Gitea in the FHS script which means that these problems should no longer occur in the docker. Our documentation used to advise people to wrap Gitea in the FHS script instead of placing it in /usr/bin but clearly someone thought that was too complicated and has removed it. Unsurprisingly this will have caused problems to resurface. Now... We have several options (for this particular problem):
The search path in 2 could depend on the directory that Gitea finds itself in or it could just be common depending on how gitea was started. The linked issue (#23301) is related but it's also likely related to incomplete configuration - in this case there should be a conf.ini but there is still an important path (APP_DATA_PATH) that is incompletely defined and so is dependent on the APP_WORK_PATH. A breaking option for dealing with this is to assert that the conf.ini must contain the absolute path to the data directory, this would be very breaking indeed as far as I can see. So to reiterate, Gitea is the way it is because it was never intended to be placed in /usr/bin or /usr/local/bin. The documentation USED to advise the use of the wrapper script for such placement. We should add this back in to the documentation. I can't understand why this was ever removed. I think we should consider a search path approach to finding the configuration if |
I don't recall which docs referenced the FHS script, and a cursory search wouldn't tell me when it existed or was removed. The install from binary docs mention setting the correct env vars, but I don't recall it ever mentioning the FHS script. (Although it may be worth adding) Do you recall where it was at? I agree with adding it somewhere, it would potentially save us some bug reports. I'm just curious to the reasoning to remove it. |
Three things that might make all this less painful:
I think all these changes could be implemented in a backwards-compatible way. |
If the AppWorkPath was stored in the app.ini, blobless clones would work in systemwide installations, see https://codeberg.org/forgejo/forgejo/issues/869 |
I just tested forgejo 1.20rc0, and it looks like the working_path/data is now stored in the app.ini (under Did you also happen to introduce an environment variable to set the path to the app.ini? |
I don't understand forgejo. Gitea's related code hasn't been changed for long time, And, if it is not absolute path, there should already be a log message to remind users (since 1.17) |
Nope, I just tested gitea 1.19.3, same as in forgejo 1.19.3.
Then I opened And here's the output I got in the console: gitea-output.txt |
I see, there is something wrong with #19815 |
No, why? The path I passed to gitea is absolute, it's just not saved in the app.ini (at least as |
And to be clear, although the code was not good, Gitea document never mentions to run the server with |
I read Gitea's document again:
That's really a longstanding problem, but I think it could be completly fixed by #25330 , but maybe the fix will only be in 1.21, I guess no backport (unless maintainers prefer to do so .....) |
Yes, I forgot the
By the way, it would be super useful if the
(or, after your fixes, |
I see, the document is not clear either. I think zeripath has explained about this problem with backgrounds #24222 (comment) If #25330 could be merged, I think I could also improve the documents about the "work path" topic, and at that time, we do not need to play with the "path tricks" any more. Thank you very much for helping investigating the problem 🙏 , I guess we are near to the complete solution now. 😄 |
IMO this should really be backported, as this is quite a serious problem - I think most people (on Linux) will use OpenSSH instead of the builtin server, and I guess that systemwide installations (or any kind of installation with non-default work dir) aren't that unusual either. And this breaks blobless clones, probably signing (#24503) and who knows what else..
I hope so =) |
FWIW, I just tried Gitea 1.20.0 rc0 with a fresh work dir, like
(and to be double-sure I also tried the variant without setting the environment variable and using And, unlike 1.19.3, it did write And while at it, I also tried setting a custom path ( |
Oh, and one more thing, about running 1.20 on a former 1.19 data dir: |
Nope, that's a side-affect by "oauth" related code.
Well, "--custom-path" is not recommended for this purpose, at least no document says doing so.
Some document words are not accurate, indeed they are crowd-contributed, so not that strict. You can also see that sometimes "GITEA_WORK_DIR" sometimes "Work Path", some code was written without careful thinking and the naming is not strict.
I believe the "read-only" is a wrong word from non-English-native contributors. They meant "0640" , which is readable-writable to the owner. You can see the demo commands below, they are 750 + 640 , not "0400" indeed. |
For what purpose? To set the custom path?
good to know |
I am pretty sure no particular purpose for now, it's just technical debt. Some options were introduced one by one, patch by patch in history, then, nowadays, they causes problems. If no time spent on them .... they would be kept there forever and cause more surprises for end users. |
As far as I know the custom path option is needed to modify the html templates and CSS files (incl. installing themes), so I wouldn't say they have no particular purpose. |
But there is already a "work path", just use "{WorkPath}/custom", that's better and clearer. |
I haven't tried it, but I assumed it would use /usr/local/bin/custom, when not explicitly specifying it with -C/--custom-path/$GITEA_CUSTOM But either way, does that solve the problem? |
#25330 stores the WORK_PATH |
That's good, because right now gitea indeed assumes that the work dir is the binary dir, if not set explicitly:
So, from the app.ini, it sets the And even if I explicitly set the work directory, the Custom File Root Path is still wrong:
This is at least consistent with https://docs.gitea.com/next/administration/config-cheat-sheet#default-configuration-non-appini-configuration:
So the default path (binary_dir/custom) has precedence over work_dir/custom. Though I doubt that work_dir/custom/ is even used/tried at all, because if I copy
I guess if it would fall back to work_dir/custom/ (that directory even exists in my testcase), it wouldn't show that warning.. No offense, but my impression is that the path handling code in Gitea overall is pretty fragile and buggy.. |
That's true ..... 🤣 and it's quite complex that's why there are many issues which are difficult to fix before refactoring. For me, I have done my best to optimize it, since it is really complex, I won't say my code is bug-free, while I think it is the right way and if there is any bug in my code, I will always fix them in the first time (as usual). |
I'm sure you will, your work (and the speed of your fixes) is incredible! :) |
# The problem There were many "path tricks": * By default, Gitea uses its program directory as its work path * Gitea tries to use the "work path" to guess its "custom path" and "custom conf (app.ini)" * Users might want to use other directories as work path * The non-default work path should be passed to Gitea by GITEA_WORK_DIR or "--work-path" * But some Gitea processes are started without these values * The "serv" process started by OpenSSH server * The CLI sub-commands started by site admin * The paths are guessed by SetCustomPathAndConf again and again * The default values of "work path / custom path / custom conf" can be changed when compiling # The solution * Use `InitWorkPathAndCommonConfig` to handle these path tricks, and use test code to cover its behaviors. * When Gitea's web server runs, write the WORK_PATH to "app.ini", this value must be the most correct one, because if this value is not right, users would find that the web UI doesn't work and then they should be able to fix it. * Then all other sub-commands can use the WORK_PATH in app.ini to initialize their paths. * By the way, when Gitea starts for git protocol, it shouldn't output any log, otherwise the git protocol gets broken and client blocks forever. The "work path" priority is: WORK_PATH in app.ini > cmd arg --work-path > env var GITEA_WORK_DIR > builtin default The "app.ini" searching order is: cmd arg --config > cmd arg "work path / custom path" > env var "work path / custom path" > builtin default ##⚠️ BREAKING If your instance's "work path / custom path / custom conf" doesn't meet the requirements (eg: work path must be absolute), Gitea will report a fatal error and exit. You need to set these values according to the error log. ---- Close #24818 Close #24222 Close #21606 Close #21498 Close #25107 Close #24981 Maybe close #24503 Replace #23301 Replace #22754 And maybe more
# The problem There were many "path tricks": * By default, Gitea uses its program directory as its work path * Gitea tries to use the "work path" to guess its "custom path" and "custom conf (app.ini)" * Users might want to use other directories as work path * The non-default work path should be passed to Gitea by GITEA_WORK_DIR or "--work-path" * But some Gitea processes are started without these values * The "serv" process started by OpenSSH server * The CLI sub-commands started by site admin * The paths are guessed by SetCustomPathAndConf again and again * The default values of "work path / custom path / custom conf" can be changed when compiling # The solution * Use `InitWorkPathAndCommonConfig` to handle these path tricks, and use test code to cover its behaviors. * When Gitea's web server runs, write the WORK_PATH to "app.ini", this value must be the most correct one, because if this value is not right, users would find that the web UI doesn't work and then they should be able to fix it. * Then all other sub-commands can use the WORK_PATH in app.ini to initialize their paths. * By the way, when Gitea starts for git protocol, it shouldn't output any log, otherwise the git protocol gets broken and client blocks forever. The "work path" priority is: WORK_PATH in app.ini > cmd arg --work-path > env var GITEA_WORK_DIR > builtin default The "app.ini" searching order is: cmd arg --config > cmd arg "work path / custom path" > env var "work path / custom path" > builtin default ##⚠️ BREAKING If your instance's "work path / custom path / custom conf" doesn't meet the requirements (eg: work path must be absolute), Gitea will report a fatal error and exit. You need to set these values according to the error log. ---- Close go-gitea#24818 Close go-gitea#24222 Close go-gitea#21606 Close go-gitea#21498 Close go-gitea#25107 Close go-gitea#24981 Maybe close go-gitea#24503 Replace go-gitea#23301 Replace go-gitea#22754 And maybe more # Conflicts: # cmd/web.go
Description
In history, Gitea's binary was designed to use the binary directory as working directory, it tries to create/use its "data"/"custom" directories in the binary path. For example: running
/usr/local/bin/gitea
makes Gitea try to use/usr/local/bin/custom
directory, which is improper/wrong, and it causes a lot of problems.POSIX users please use https://github.com/go-gitea/gitea/tree/main/contrib/fhs-compliant-script , do not put Gitea binary into
/usr/loca/bin
directory -- unless you are 100% sure about the details."custom" bug
A feedback from discord
Update gitea from 1.15.6 to 1.15.7 (and then 1.19.1):
I'm using the script in
contrib/upgrade.sh
and as far as I'm concerned I have never used this "custom" folder, why is it needed? (I am using sqlite3 as well)I don't get why it's trying to read/write in that particular folder and not from /var/lib/gitea/custom
The text was updated successfully, but these errors were encountered: