diff --git a/lib/data/templates/postgresql/postgresql.service b/lib/data/templates/postgresql/postgresql.service.erb similarity index 85% rename from lib/data/templates/postgresql/postgresql.service rename to lib/data/templates/postgresql/postgresql.service.erb index 3976e51..3ddaa20 100644 --- a/lib/data/templates/postgresql/postgresql.service +++ b/lib/data/templates/postgresql/postgresql.service.erb @@ -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 diff --git a/lib/execute.rb b/lib/execute.rb index fd495d4..f5c80af 100644 --- a/lib/execute.rb +++ b/lib/execute.rb @@ -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 diff --git a/lib/setup/postgresql.rb b/lib/setup/postgresql.rb index 98652b1..fbbb190 100644 --- a/lib/setup/postgresql.rb +++ b/lib/setup/postgresql.rb @@ -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 diff --git a/recipes/postgresql/debian.yml b/recipes/postgresql/debian.yml index fa0d991..fa81f49 100644 --- a/recipes/postgresql/debian.yml +++ b/recipes/postgresql/debian.yml @@ -12,6 +12,8 @@ packages: - libedit-dev repository: + # Original repository + # https://git.postgresql.org/gitweb/?p=postgresql.git url: https://github.com/postgres/postgres.git branch: REL_17_5 version: 17.5