add unix socket for postgres

This commit is contained in:
Artur Gurgul1 2025-08-08 10:17:01 +02:00
parent 2054a68af0
commit 2289379ad5
9 changed files with 32 additions and 29 deletions

View file

@ -32,7 +32,7 @@ module Setup
end
system("sudo mkdir -p #{context.data_dir}")
system("sudo chown #{context.user_name}:services #{context.data_dir}")
system("sudo -u postgresql #{File.join(context.bin_dir, "/bin/initdb")} -D #{context.data_dir}")
system("sudo -u postgres #{File.join(context.bin_dir, "/bin/initdb")} -D #{context.data_dir} --username=postgres")
end
def self.setup_systemd(context)
@ -41,12 +41,15 @@ module Setup
pg_hba_path = "#{File.join(context.data_dir, "pg_hba.conf")}"
write_as(context.user_name, pg_hba_path, pg_hba)
# TODO: move this to user module
uid = Etc.getpwnam(context.user_name.to_s).uid
socket_path = "/run/user/#{uid}"
## TODO: move this to user module
#uid = Etc.getpwnam(context.user_name.to_s).uid
#socket_path = "/run/user/#{uid}"
socket_path = "/run/user/#{context.user_name}"
#socket_path = "/tmp"
system("sudo mkdir -p #{socket_path}")
system("sudo chown #{context.user_name}:services #{socket_path}")
system("sudo chmod 700 #{socket_path}")
system("sudo chmod 711 #{socket_path}")
postgresql_conf = render("postgresql.conf", unix_socket: socket_path)
@ -54,17 +57,17 @@ module Setup
write_as(context.user_name, postgresql_conf_path, postgresql_conf)
postgres_service = render(
"postgresql.service",
"postgres.service",
postgres_bin: File.join(context.bin_dir, "/bin/postgres"),
version: context.version,
database_dir: context.data_dir
)
postgres_service_path = "/etc/systemd/system/postgresql.service"
postgres_service_path = "/etc/systemd/system/postgres.service"
write_as("root", postgres_service_path, postgres_service)
system("sudo systemctl daemon-reexec")
system("sudo systemctl daemon-reload")
system("sudo systemctl enable postgresql")
system("sudo systemctl start postgresql")
system("sudo systemctl enable postgres")
system("sudo systemctl start postgres")
# debug service
# sudo systemctl daemon-reexec && sudo systemctl daemon-reload && sudo systemctl restart postgresql.service