Skip to content

Allow script to run without init system (in containers) #38

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

SlouchyButton
Copy link
Member

@SlouchyButton SlouchyButton commented Jun 11, 2025

This change detects whether system is running without systemd as PID1, and if so it refrains from using any systemctl commands (that normally need systemd to be running as PID1).

The script will parse the service file directly (specified by autotools configuration) and try to figure out the datadir from there. If that also fails or is not possible, added --datadir option to override the datadir and use that for upgrade/initialization.

Updated readme to include usage, how to debug the script and converted to markdown for more up-to-date look.

Fixes: #26

Adds argument --datadir as a possible fallback for user that would
like to set custom data directory.

Adds usage section to readme.
@SlouchyButton SlouchyButton requested a review from fila43 June 11, 2025 13:30
use `./postgresql-setup --upgrade`.

If your distribution doesn't include this
script with PostgreSQL and you are using this on your own, please update
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I understand it correctly that you mean users who want to use it on other distributions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, from what I understood this script is completely distro/os agnostic (as long as u have bash) and you could configure the paths.

And with the addition of not being dependent on systemd you have even more possibilities with this script. I mean, theoretically it could even be used on macOS with bash and postgresql installed (via brew, for example). Only thing that you would need is to fix the paths via autotools config (maybe something is hardcoded somewhere, but mostly just autotools).

@fila43
Copy link
Contributor

fila43 commented Jun 12, 2025

It makes sense to me, but I am not an expert in bash. What is your opinion from the bash perspective @praiskup ?

@praiskup
Copy link
Member

I don't have time for reviewing this, sorry.

Copy link

@duzda duzda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @SlouchyButton,

Please address some of the mentioned issues.

  1. I'd move the Fixes: https://github.com/devexp-db/postgresql-setup/issues/26 to the Allow initdb and upgrade without systemd running commit, as the other commits update README, they don't really fix the issue described.

  2. Apart from listing requirements, I'd consider adding simple one liner dnf install autoconf ..., that is more newbie friendly.

Comment on lines +404 to +405
local systemd_env="$(cat "${service_file}")" \
|| { return; }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very strange syntax? Might be ok to keep though, consider adding comment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's reused from other similar functions as the one exactly above 'handle_service_env()'. It is probably more readable to just pipe the file using << directly into the loop. But not sure really, I just tried to be consistent, even tho in the other functions we are not working with files at all - so we wouldn't be able to use << there.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cat is fine, although, yes, you should use pipes, that's what the general guidelines say, I was pointing at the { return; } as it might not be immediately obvious.

Suggestions from code review

Co-authored-by: David Hanina <25201406+duzda@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

postgresql-setup --init should work in container environment
4 participants