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]
|
[Service]
|
||||||
Type=notify
|
Type=notify
|
||||||
|
|
||||||
User=postgres
|
User=postgresql
|
||||||
Group=services
|
Group=servicesql
|
||||||
|
|
||||||
ExecStart=<%= postgres_bin %> -D <%= database_dir %>/data
|
ExecStart=<%= postgres_bin %> -D <%= database_dir %>/data
|
||||||
ExecReload=/bin/kill -HUP $MAINPID
|
ExecReload=/bin/kill -HUP $MAINPID
|
||||||
|
|
|
@ -79,6 +79,8 @@ module Execute
|
||||||
pdata = Make.context(name)
|
pdata = Make.context(name)
|
||||||
bin_dir = pdata.get_prefix
|
bin_dir = pdata.get_prefix
|
||||||
data_dir = "/data/#{pdata.name}/#{pdata.version.split(".").first}"
|
data_dir = "/data/#{pdata.name}/#{pdata.version.split(".").first}"
|
||||||
|
puts data_dir
|
||||||
|
exit -1
|
||||||
service_install_context = ServiceInstallContext.new(
|
service_install_context = ServiceInstallContext.new(
|
||||||
bin_dir, data_dir, name, pdata.version, @options.forced
|
bin_dir, data_dir, name, pdata.version, @options.forced
|
||||||
)
|
)
|
||||||
|
|
|
@ -9,6 +9,14 @@ module Setup
|
||||||
module PostgreSQL
|
module PostgreSQL
|
||||||
extend Templates
|
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
|
# attr_accessor :te
|
||||||
|
@ -28,24 +36,31 @@ module Setup
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.setup_systemd(context)
|
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)
|
postgres_service = render(
|
||||||
# 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",
|
"postgresql.service",
|
||||||
postgres_bin: File.join(context.bin_dir, "/bin/postgres"),
|
postgres_bin: File.join(context.bin_dir, "/bin/postgres"),
|
||||||
version: context.version,
|
version: context.version,
|
||||||
database_dir: context.data_dir
|
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_context = Execute::UserInstallContext.new(context.user_name, :service)
|
||||||
User.install(user_context)
|
User.install(user_context)
|
||||||
init_db(context)
|
init_db(context)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue