Add setting up systemd

This commit is contained in:
Artur Gurgul1 2025-08-07 19:41:04 +02:00
parent bc0f9db31d
commit 688d23527f
3 changed files with 31 additions and 14 deletions

View file

@ -9,7 +9,15 @@ module Setup
module PostgreSQL
extend Templates
def self.write_as(user, path, content)
puts "wriiting by #{user} to #{path}"
# If executed as root we can just use File.write
# File.write(postgresql_conf_path, postgresql_conf_content)
IO.popen(["sudo", "-u", user.to_s, "tee", path], "w") do |io|
io.write(content)
end
end
# attr_accessor :te
@ -28,24 +36,31 @@ module Setup
end
def self.setup_systemd(context)
puts "DataDir: #{context.data_dir}"
pg_hba = render("pg_hba.conf")
pg_hba_path = "#{File.join(context.data_dir, "pg_hba.conf")}"
write_as(context.user_name, pg_hba_path, pg_hba)
end
postgresql_conf = render("postgresql.conf")
postgresql_conf_path = "#{File.join(context.data_dir, "postgresql.conf")}"
write_as(context.user_name, postgresql_conf_path, postgresql_conf)
def self.install(context)
# puts context.bin_dir
#make_config
# pg_hba = render("pg_hba.conf")
#
# # test = render("test", te: "This is a test string")
# posgresql_conf = render("postgresql")
service = render(
postgres_service = render(
"postgresql.service",
postgres_bin: File.join(context.bin_dir, "/bin/postgres"),
version: context.version,
database_dir: context.data_dir
)
# puts service
)
postgres_service_path = "/etc/systemd/system/postgresql.service"
write_as("root", postgres_service_path, postgres_service)
system("sudo systemctl daemon-reload")
system("sudo systemctl enable postgresql")
system("sudo systemctl start postgresql")
end
def self.install(context)
user_context = Execute::UserInstallContext.new(context.user_name, :service)
User.install(user_context)
init_db(context)