Skip to content

Commit

Permalink
check and only allow to create database in a mount point
Browse files Browse the repository at this point in the history
  • Loading branch information
ailisp committed Oct 5, 2017
1 parent b9e7606 commit 84b62a7
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "pathname"
require "util/postgres_admin"
require "pg"
require "linux_admin"

RAILS_ROOT ||= Pathname.new(__dir__).join("../../../")

Expand Down Expand Up @@ -67,6 +68,9 @@ def ask_questions

def choose_disk
@disk = ask_for_disk("database disk")
error_message = "The disk for database must be a mount point"
raise error_message unless disk || pg_mount_point?
disk
end

def initialize_postgresql_disk
Expand Down Expand Up @@ -108,7 +112,7 @@ def post_activation
private

def mount_point
Pathname.new(ENV.fetch("APPLIANCE_PG_MOUNT_POINT"))
PostgresAdmin.mount_point
end

def copy_template(src, src_dir = self.class.postgresql_template, dest_dir = PostgresAdmin.data_directory)
Expand All @@ -121,6 +125,10 @@ def copy_template(src, src_dir = self.class.postgresql_template, dest_dir = Post
end
end

def pg_mount_point?
LinuxAdmin::LogicalVolume.mount_point_exists?(mount_point)
end

def run_initdb
AwesomeSpawn.run!("service", :params => {nil => [PostgresAdmin.service_name, "initdb"]})
end
Expand Down

0 comments on commit 84b62a7

Please sign in to comment.