Clean up postgresql startup
Closed this issue · 6 comments
The pgsql doesn't initialized correctly and you never write error recovery handler for pgsql after docker container restart.
Also docker is no-daemon design. Please stop using init.d/systemd even it is working....
Fixed.
Before all:
Please accept my apology. There're some misunderstand here. So sorry for that.
According to Docker Official Reference
- If you need to handle the shutdown action for container, you must ensure the
entrypoint.sh
can handle the signal. In the issue which was closed and opened by me, I mistakenly take the error recovery responsibility to the script. **However, after some tests, I found it could be handled in pgsql itself properly. Just will cost a little time(some seconds). ** You could still optimize it.
According to the log of the container I run for test
- The "error recovery handler" feature request is a mistake I made. All of this is a bug of initdb.
About init.d
- Worked, so just left it here for I'm lazy.
Next?
PR is on the way...
So, what have I done now?
Assume
You start a container with an empty data persistent volume.
Expected behavior
All worked fine.
Actual Behavior
It won't start due to "not-existing, not-initialized, not-correct-owner, not-correct-file-system-permission" data folder.
What's behind?
- The initial volume is empty without any folder. But
pg_ctl initdb
need a specific folder structure. - OpenVAS scanner MUST init db by itself but it haven't done correctly in the version this dockerfile use.
- Due to the two errors above, the pgsql server daemon won't start.
- OpenVAS manager failed to connect to pgsql server. So all died.
My solution (What will I do in PR)
In DockerFile
:
- Add
arachni
- Add missed dependencies such as
curl
andwget
- Modify system locale to ensure that the database must encoded in UTF-8 and search engine is in English.
- Create pgsql config folder
/etc/postgres
and change the owner topostgres
- Create pgsql run folder
/var/run/postgresql/10-main.pg_stat_tmp
and change the owner topostgres
In entrypoint.sh
of pgsql
:
- mkdir for correct position while using volume and change the owner to corresponding one.
- move restart pgsql server to the location before start
gvmd
and after startopenvassd
- after
openvassd
, sleep enough time to let it flush the data cache - after sleep, do initdb, it will exit automatically without doing anything if db has already been initialized.
- check if db is ready
- start
gvmd
andgsad
now and enjoy it.
Still building the image in Docker Hub CI, will test later and give a response.
by the way, have you ever meet this condition?
Thanks for the help!
Did you pull "master" from the repo?
I think that:
All the dependencies should exist, and psql should work out of the box?
The "only" thing that I didn't fix is decouple psql from init.d :)
About the greenbone/gsa#1364 condition. I cant recall that it happened to me before.
--
Regards Falk
Thank you so much
Closed for lack of input.