This script automates the installation and configuration of PostgreSQL on a remote server via SSH.
To use this script, execute the following command:
python install_postgres.py <host>Replace with the hostname or IP address of the target server.
Python 3.x
paramiko library (`pip install paramiko`)
- The script provides two ways to connect to the provided host - via an SSH key, or via username/password if the former attempt is unsuccesfull.
sudosupport:- You cannot simply use
sudo su - usernamein anexec_commandbefore the command that needs root access, because each call toexec_commandruns in its own subshell, as such the changes will not propagate back to the main session. - I tried to overcome this issue by writing a simple function-wrapper around
exec_command, which (along side proper exceptions handling) checks if the command requires sudo perms, and if it does, handles admin password input if needed.
- You cannot simply use
- Script is designed to work on Debian-based distros and on the latest postgresql version (usage of
aptand the hardcoded path to the .conf file).- It is possible to adapt the solution to check both for an existing package manager by checking the distro first (
debian/SuSE/redhat/gentoo/alpine/arch/..) in the folder/etc/os-release
- It is possible to adapt the solution to check both for an existing package manager by checking the distro first (
В целом обратная связь по заданию
"Установка на Debian 12 не сработала из-за хардкода версии postgres в скрипте
(в Debian 12 - postgres 15). После правки скрипта postgres установился, но не прошла проверка
доступности из-за некорректной правки pg_hba.conf.
Плюсы:
* Хороший код
* Самая продуманная обработка ошибок Paramiko
* В readme описаны некоторые ограничения и мысли по реализации.
Минусы:
* Нет файла requirements.txt
* Программа не выдаёт статус выполнения инсталляции
* Программа ожидает лишних команд при запуске (это не соответствует исходному заданию)"
Tkachenko Nikita
Moscow, Higher School of Economics: 3-rd year, Applied Mathematics, GPA: 7.3
My CV: link