Closed polarathene closed 3 years ago
Checking that a file is non-zero in size is easy enough to do but it only partially solves the issue because if the file is non-zero in size but still invalid it's going to have the same problem. Unfortunately the error handling when it comes to the contents of the .env itself is part of Bookstack and not our logic.
Unfortunately the error handling when it comes to the contents of the .env itself is part of Bookstack and not our logic.
Ah ok, shall I forward the issue to Bookstack then? I think it belongs here since the container is creating and modifying .env
?
TL;DR:
I guess the better solution is to just re-create the .env
file if it's 0 bytes?
I'm not sure of any other situation where .env
would be missing the expected vars to replace with sed
. This is probably a niche issue to run into, but it is confusing when you had a valid config that's unmodified result in a container failing to work.
By invalid I mean any other situation where the .env file exists but the data inside is not valid for the purposes of Bookstack being able to parse it; file gets corrupted, user pastes incorrectly-escaped data in or accidentally overwrites it with another file, etc. Bookstack isn't failing to start because our sed fails, it's failing to start because the .env doesn't have valid data in it.
It's not so much that we can't detect and fix your specific issue it's more that generally speaking we don't like to touch any existing user data if we can avoid it, no matter the state, because we can't be sure it's not intentional and we don't want angry users demanding to know why we overwrote their data. If people want to do weird, unsupported stuff with their containers, that's up to them.
That said I don't see any reason we couldn't log a warning in the event that we detect a 0-byte .env on startup, so there's at least an indication of a problem.
I understand and roughly agree with you :+1:
Issue summary:
.env
again on restart prior to my knowledge of a lack of disk space, thus broke itself due to I/O error.A warning would be good, but I can't think of any valid reason not to treat it the same as a missing .env
file. I debated your response in the collapsed section below if that's of any interest.
If you think it would be worthwhile to implement, awesome! If not, well anyone else who runs into the same issue will probably find this issue eventually :sweat_smile:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Expected Behavior
Better handling or warning in log of potential problem.
Could validate an
.env
file has required vars before starting the service, or just checking for a zero sized file should at least avoid this scenario.Current Behavior
If
.env
is an empty (0 bytes) file, the current behaviour is to ignore updating the.env
:https://github.com/linuxserver/docker-bookstack/blob/ed91128c6746ec77ef3a6402de745559144b80e5/root/etc/cont-init.d/50-config#L7-L9
This prevents all
.env
update logic viased
replace operations. Which in turn causes Bookstack to fail to start:This scenario shouldn't happen, but affected a production setup that had been running fine for about 2 years when the host system ran out of disk space for the volume the container mounted to persist data. The container restarted itself at some point, and some condition to write or write to
.env
on disk (perhaps due to disk write error) resulted in the file becoming empty/blank.It was unclear initially why the service was failing to restore after resolving the disk space issue with the given failure message above, especially since the
docker-compose.yml
ENV (separate from internal container managed.env
file) was valid which the error output implied was not being used.Steps to Reproduce
.env
file to be empty.Environment
OS: Linux CPU architecture: x86_64 How docker service was installed: Official distro repo
Command used to create docker container (run/create/compose/screenshot)
/docker/docker-compose.yml
example (_generates default network based on directory name, thusdocker_default
like above example error snippet_):Docker logs