mirror of
https://github.com/ubicloud/ubicloud.git
synced 2025-10-06 06:41:57 +08:00
For major version upgrades, we change the boot image to allow running multiple versions of PG simultaneously. For this, we only **download** the relevant packages for all supported PG versions at image generation time. Additionally, the image generation step places the required package list as text files at /usr/local/share/postgresql/packages/#{version}.txt,common.txt. While initializing a new server, we install the required packages by referring to the package list. With the download already completed at image generation time, this step should be fairly quick to allow for quick startup and upgrades. For rolling out this change , we need to ensure all older servers have these files in place.
33 lines
957 B
Ruby
33 lines
957 B
Ruby
# frozen_string_literal: true
|
|
|
|
require_relative "../../common/lib/util"
|
|
require "logger"
|
|
|
|
class PostgresSetup
|
|
def initialize(version)
|
|
@version = version
|
|
end
|
|
|
|
def setup_packages
|
|
r "sudo apt-get -y install $(cat /usr/local/share/postgresql/packages/#{@version}.txt | tr \"\n\" \"\")"
|
|
r "sudo apt-get -y install $(cat /usr/local/share/postgresql/packages/common.txt | tr \"\n\" \"\")"
|
|
end
|
|
|
|
def setup_data_directory
|
|
r "chown postgres /dat"
|
|
|
|
# Below commands are required for idempotency
|
|
r "rm -rf /dat/#{@version}"
|
|
r "rm -rf /etc/postgresql/#{@version}"
|
|
|
|
r "echo \"data_directory = '/dat/#{@version}/data'\" | sudo tee /etc/postgresql-common/createcluster.d/data-dir.conf"
|
|
end
|
|
|
|
def create_cluster
|
|
r "pg_createcluster #{@version} main --port=5432 --start --locale=C.UTF8"
|
|
end
|
|
|
|
def teardown
|
|
r "sudo apt-get -y remove $(cat /usr/local/share/postgresql/packages/#{@version}.txt | tr \"\n\" \"\")"
|
|
end
|
|
end
|