generate systemd for postgres

This commit is contained in:
Artur Gurgul1 2025-08-07 14:23:42 +02:00
parent ed7fc9aa7f
commit 29a9b08573
4 changed files with 63 additions and 24 deletions

View file

@ -8,7 +8,7 @@ Type=notify
User=postgres
Group=services
ExecStart=<%= prefix %>/bin/postgres -D <%= database_path %>/data
ExecStart=<%= postgres_bin %> -D <%= database_dir %>/data
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
TimeoutSec=300

View file

@ -15,6 +15,17 @@ require 'ostruct'
# dat command service zulip
module Execute
class ServiceInstallContext
attr_accessor :bin_dir, :data_dir, :version, :user_name
def initialize(bin_dir, data_dir, user_name, version)
@bin_dir = bin_dir
@data_dir = data_dir
@user_name = user_name
@version = version
end
end
def dependency(name)
puts "Checking for #{name}..."
@ -34,15 +45,44 @@ module Execute
Gem::Specification::find_all_by_name(name).any?
end
def postgres
def get_install_executor(name)
require 'make'
pdata = Make.context(name)
bin_dir = pdata.get_prefix
data_dir = "/data/#{pdata.name}/#{pdata.version.split(".").first}"
service_install_context = ServiceInstallContext.new(
bin_dir, data_dir, name, pdata.version
)
case name
when :postgresql
require 'setup/postgresql'
puts 'installing postgres'
Setup::PostgreSQL.install
-> { Setup::PostgreSQL.install(service_install_context) }
# ->(context) {
# Setup::PostgreSQL.install(context)
# }
else
raise "Can't find the executor"
end
end
def execute_with_context(context)
end
# def postgres
# require 'setup/postgresql'
# Setup::PostgreSQL.install
# end
def service(name)
executor = get_install_executor(name)
#executor.call(service_install_context)
executor.call
exit -1
if block_given?
context = OpenStruct.new
# service context
output = yield context
puts output
puts "context: #{context}"
@ -62,16 +102,12 @@ module Execute
end
def self.file(options)
require 'make'
puts Make.context("postgresql")
puts "options: #{options}"
dsl = Object.new
dsl.extend(Execute)
# Configfile
path = File.join(Dir.pwd, options.name || "./Configfile")
dsl.instance_eval(File.read(path), path)
# Execute the config
end
end

View file

@ -1,7 +1,9 @@
module Setup
require_relative '../templates'
# dat execute postgres
# example.rcp
module PostgreSQL
extend Templates
@ -9,26 +11,25 @@ module Setup
# attr_accessor :te
def self.init_db
def self.init_db(context)
system(" -D /opt/pgsql/16/data")
end
def self.make_config
pg_hba = render("pg_hba.conf")
# test = render("test", te: "This is a test string")
posgresql_conf = render("postgresql")
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(
"postgresql.service",
prefix: "/pkg/postgresql/REL_17_5/",
version: "16.5",
data_url: "/data/postgresql/16/"
postgres_bin: File.join(context.bin_dir, "/bin/postgres"),
version: context.version,
database_dir: context.data_dir
)
puts test
end
def self.install
make_config
puts service
end
end
end