refactor: Migrate PostgreSQL installer to Podman
- Replaced the previous systemd-based PostgreSQL installer with a Podman-based solution. This simplifies the installation process and improves compatibility across different Linux distributions. - The new installer uses Podman containers to manage the PostgreSQL database, eliminating the need for complex systemd configurations and package management. - This change enhances portability and reduces the risk of conflicts with existing system packages. The destroy_ function now cleanly removes the Podman container. The installed_ and check functions now verify the container's health. Co-authored-by: mario <mariobassem12@gmail.com>
This commit is contained in:
@@ -4,8 +4,18 @@ import freeflowuniverse.herolib.osal
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.installers.virt.podman as podman_installer
|
||||
import freeflowuniverse.herolib.osal.zinit
|
||||
import os
|
||||
|
||||
fn installed_() !bool {
|
||||
mut cfg := get()!
|
||||
mut podman := podman_installer.get()!
|
||||
podman.install()!
|
||||
cmd := 'podman healthcheck run ${cfg.container_name}'
|
||||
result := os.execute(cmd)
|
||||
|
||||
if result.exit_code != 0 {
|
||||
return error("Postgresql container isn't running: ${result.output}")
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -52,41 +62,13 @@ fn stop_post() ! {
|
||||
}
|
||||
|
||||
fn destroy_() ! {
|
||||
mut mydb := get()!
|
||||
mydb.destroy()!
|
||||
// remove the podman postgresql container
|
||||
mut cfg := get()!
|
||||
cmd := 'podman rm -f ${cfg.container_name}'
|
||||
result := os.execute(cmd)
|
||||
|
||||
// mut cfg := get()!
|
||||
// osal.rm("
|
||||
// ${cfg.path}
|
||||
// /etc/postgresql/
|
||||
// /etc/postgresql-common/
|
||||
// /var/lib/postgresql/
|
||||
// /etc/systemd/system/multi-user.target.wants/postgresql
|
||||
// /lib/systemd/system/postgresql.service
|
||||
// /lib/systemd/system/postgresql@.service
|
||||
// ")!
|
||||
|
||||
// c := '
|
||||
|
||||
// #dont die
|
||||
// set +e
|
||||
|
||||
// # Stop the PostgreSQL service
|
||||
// sudo systemctl stop postgresql
|
||||
|
||||
// # Purge PostgreSQL packages
|
||||
// sudo apt-get purge -y postgresql* pgdg-keyring
|
||||
|
||||
// # Remove all data and configurations
|
||||
// sudo userdel -r postgres
|
||||
// sudo groupdel postgres
|
||||
|
||||
// # Reload systemd configurations and reset failed systemd entries
|
||||
// sudo systemctl daemon-reload
|
||||
// sudo systemctl reset-failed
|
||||
|
||||
// echo "PostgreSQL has been removed completely"
|
||||
|
||||
// '
|
||||
// osal.exec(cmd: c)!
|
||||
if result.exit_code != 0 {
|
||||
return error("Postgresql container isn't running: ${result.output}")
|
||||
}
|
||||
console.print_header('Postgresql container removed')
|
||||
}
|
||||
|
||||
@@ -41,14 +41,14 @@ pub fn (mut server Postgresql) check() ! {
|
||||
|
||||
db.exec('SELECT version();') or { return error('postgresql could not do select version') }
|
||||
|
||||
cmd := 'podman healthcheck run ${server.name}'
|
||||
cmd := 'podman healthcheck run ${server.container_name}'
|
||||
result := os.execute(cmd)
|
||||
|
||||
if result.exit_code != 0 {
|
||||
return error("Postgresql container isn't healthy: ${result.output}")
|
||||
}
|
||||
|
||||
container_id := 'podman container inspect default --format {{.Id}}'
|
||||
container_id := 'podman container inspect ${server.container_name} --format {{.Id}}'
|
||||
container_id_result := os.execute(container_id)
|
||||
if container_id_result.exit_code != 0 {
|
||||
return error('Cannot get the container ID: ${result.output}')
|
||||
|
||||
@@ -98,7 +98,8 @@ pub fn play(args_ PlayArgs) ! {
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
mut p := install_action.params
|
||||
cfg_play(p)!
|
||||
mycfg := cfg_play(p)!
|
||||
set(mycfg)!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,29 +15,32 @@ pub fn heroscript_default() !string {
|
||||
host: 'localhost'
|
||||
port: 5432
|
||||
volume_path:'/var/lib/postgresql/data'
|
||||
container_name: 'herocontainer_postgresql'
|
||||
"
|
||||
return heroscript
|
||||
}
|
||||
|
||||
pub struct Postgresql {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
user string = 'postgres'
|
||||
password string = 'postgres'
|
||||
host string = 'localhost'
|
||||
volume_path string = '/var/lib/postgresql/data'
|
||||
port int = 5432
|
||||
container_id string
|
||||
name string = 'default'
|
||||
user string = 'postgres'
|
||||
password string = 'postgres'
|
||||
host string = 'localhost'
|
||||
volume_path string = '/var/lib/postgresql/data'
|
||||
container_name string = 'herocontainer_postgresql'
|
||||
port int = 5432
|
||||
container_id string
|
||||
}
|
||||
|
||||
fn cfg_play(p paramsparser.Params) !Postgresql {
|
||||
mut mycfg := Postgresql{
|
||||
name: p.get_default('name', 'default')!
|
||||
user: p.get_default('user', 'postgres')!
|
||||
password: p.get_default('password', 'postgres')!
|
||||
host: p.get_default('host', 'localhost')!
|
||||
port: p.get_int_default('port', 5432)!
|
||||
volume_path: p.get_default('path', '/var/lib/postgresql/data')!
|
||||
name: p.get_default('name', 'default')!
|
||||
user: p.get_default('user', 'postgres')!
|
||||
password: p.get_default('password', 'postgres')!
|
||||
host: p.get_default('host', 'localhost')!
|
||||
port: p.get_int_default('port', 5432)!
|
||||
volume_path: p.get_default('path', '/var/lib/postgresql/data')!
|
||||
container_name: p.get_default('container_name', 'herocontainer_postgresql')!
|
||||
}
|
||||
return mycfg
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user