2025-08-06 16:50:03 +02:00
|
|
|
|
|
|
|
module Setup
|
|
|
|
require_relative '../templates'
|
2025-08-07 16:29:11 +02:00
|
|
|
require_relative "../user"
|
|
|
|
require_relative "../execute"
|
2025-08-07 14:23:42 +02:00
|
|
|
# dat execute postgres
|
|
|
|
# example.rcp
|
|
|
|
|
2025-08-06 16:50:03 +02:00
|
|
|
module PostgreSQL
|
|
|
|
extend Templates
|
|
|
|
|
2025-08-07 13:02:01 +02:00
|
|
|
|
|
|
|
|
2025-08-06 16:50:03 +02:00
|
|
|
# attr_accessor :te
|
|
|
|
|
2025-08-07 14:23:42 +02:00
|
|
|
def self.init_db(context)
|
2025-08-07 17:36:47 +02:00
|
|
|
puts "Mode, isForced #{context.forced}"
|
|
|
|
if Dir.exist?(context.data_dir)
|
|
|
|
if context.forced
|
|
|
|
puts("sudo rm -rf #{context.data_dir}")
|
|
|
|
else
|
|
|
|
raise "PostgreSQL data already exists"
|
|
|
|
end
|
|
|
|
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}")
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.setup_systemd(context)
|
|
|
|
|
2025-08-07 13:02:01 +02:00
|
|
|
end
|
2025-08-06 16:50:03 +02:00
|
|
|
|
2025-08-07 14:23:42 +02:00
|
|
|
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")
|
2025-08-07 13:02:01 +02:00
|
|
|
service = render(
|
|
|
|
"postgresql.service",
|
2025-08-07 14:23:42 +02:00
|
|
|
postgres_bin: File.join(context.bin_dir, "/bin/postgres"),
|
|
|
|
version: context.version,
|
|
|
|
database_dir: context.data_dir
|
2025-08-07 13:02:01 +02:00
|
|
|
)
|
2025-08-07 16:29:11 +02:00
|
|
|
# puts service
|
2025-08-07 14:23:42 +02:00
|
|
|
|
2025-08-07 16:29:11 +02:00
|
|
|
user_context = Execute::UserInstallContext.new(context.user_name, :service)
|
|
|
|
User.install(user_context)
|
2025-08-07 17:36:47 +02:00
|
|
|
init_db(context)
|
|
|
|
setup_systemd(context)
|
2025-08-06 16:50:03 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|