Add setting up systemd
This commit is contained in:
parent
bc0f9db31d
commit
688d23527f
3 changed files with 31 additions and 14 deletions
|
@ -5,8 +5,8 @@ After=network.target
|
|||
[Service]
|
||||
Type=notify
|
||||
|
||||
User=postgres
|
||||
Group=services
|
||||
User=postgresql
|
||||
Group=servicesql
|
||||
|
||||
ExecStart=<%= postgres_bin %> -D <%= database_dir %>/data
|
||||
ExecReload=/bin/kill -HUP $MAINPID
|
||||
|
|
|
@ -79,6 +79,8 @@ module Execute
|
|||
pdata = Make.context(name)
|
||||
bin_dir = pdata.get_prefix
|
||||
data_dir = "/data/#{pdata.name}/#{pdata.version.split(".").first}"
|
||||
puts data_dir
|
||||
exit -1
|
||||
service_install_context = ServiceInstallContext.new(
|
||||
bin_dir, data_dir, name, pdata.version, @options.forced
|
||||
)
|
||||
|
|
|
@ -9,6 +9,14 @@ 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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue