Commit da97c5a3 by Owo Sugiana

Di konfigurasi tidak perlu lagi pg_stop dan pg_start

1 parent edf738bd
...@@ -2,3 +2,4 @@ test* ...@@ -2,3 +2,4 @@ test*
__pycache__ __pycache__
dist dist
*egg-info *egg-info
build
0.6 5-6-2021
------------
- Bug fixed is_mirror() saat Postgres versi 13
- Di konfigurasi tidak perlu lagi pg_stop dan pg_start
0.5.1 19-5-2021 0.5.1 19-5-2021
--------------- ---------------
- Perintah VACUUM tidak lagi dengan opsi FULL karena akan menghapus file yang - Perintah VACUUM tidak lagi dengan opsi FULL karena akan menghapus file yang
......
...@@ -5,7 +5,7 @@ memasangnya:: ...@@ -5,7 +5,7 @@ memasangnya::
$ python3 -m venv env $ python3 -m venv env
$ env/bin/pip install --upgrade pip $ env/bin/pip install --upgrade pip
$ env/bin/pip install git+https://git.opensipkd.com/sugiana/maintenance $ env/bin/pip install git+https://git.opensipkd.com/sugiana/maintenance.git
Buat file konfigurasi ``maintenance.ini``:: Buat file konfigurasi ``maintenance.ini``::
...@@ -21,9 +21,6 @@ Buat file konfigurasi ``maintenance.ini``:: ...@@ -21,9 +21,6 @@ Buat file konfigurasi ``maintenance.ini``::
systemctl start nginx.service systemctl start nginx.service
systemctl start cron.service systemctl start cron.service
pg_stop = systemctl stop postgresql.service
pg_start = systemctl start postgresql.service
pg_lib_dir = /usr/lib/postgresql pg_lib_dir = /usr/lib/postgresql
pg_conf_dir = /etc/postgresql pg_conf_dir = /etc/postgresql
...@@ -56,11 +53,10 @@ Buat file konfigurasi ``maintenance.ini``:: ...@@ -56,11 +53,10 @@ Buat file konfigurasi ``maintenance.ini``::
handlers = console, file handlers = console, file
level = DEBUG level = DEBUG
Konfigurasi ini dibuat untuk Debian 8 ke atas yaitu yang sudah menerapkan Sesuaikan baris ``database`` yang berisi nama database yang akan di-backup.
``systemd``. Sesuaikan baris ``database`` yang berisi nama database yang akan Baris ``before`` biasanya diisi dengan perintah untuk menghentikan daemon yang
di-backup. Baris ``before`` biasanya diisi dengan perintah untuk menghentikan menggunakan database, sedangkan baris ``after`` untuk menghidupkannya kembali
daemon yang menggunakan database, sedangkan baris ``after`` untuk setelah proses backup selesai.
menghidupkannya kembali setelah proses backup selesai.
Selanjutnya jalankan sebagai root:: Selanjutnya jalankan sebagai root::
...@@ -102,7 +98,7 @@ record pada tabel ``log_file``. Jika pada *log file* terdapat beberapa baris ...@@ -102,7 +98,7 @@ record pada tabel ``log_file``. Jika pada *log file* terdapat beberapa baris
yang sebenarnya sebuah satu-kesatuan seperti pada *Python exception* maka akan yang sebenarnya sebuah satu-kesatuan seperti pada *Python exception* maka akan
disimpan ke dalam sebuah record saja. disimpan ke dalam sebuah record saja.
Buatlah databasenya terlebih dahulu. Buatlah file konfigurasi ``log2db.ini``:: Buatlah databasenya terlebih dahulu, lalu buat file konfigurasi ``log2db.ini``::
[main] [main]
db_url = postgresql://user:pass@localhost:5432/db db_url = postgresql://user:pass@localhost:5432/db
......
...@@ -10,9 +10,6 @@ after = ...@@ -10,9 +10,6 @@ after =
systemctl start nginx.service systemctl start nginx.service
systemctl start cron.service systemctl start cron.service
pg_stop = systemctl stop postgresql.service
pg_start = systemctl start postgresql.service
pg_lib_dir = /usr/lib/postgresql pg_lib_dir = /usr/lib/postgresql
pg_conf_dir = /etc/postgresql pg_conf_dir = /etc/postgresql
......
...@@ -55,10 +55,36 @@ def run_event(event): ...@@ -55,10 +55,36 @@ def run_event(event):
run(script) run(script)
def is_systemd():
script = '/lib/systemd/system/postgresql.service'
return os.path.exists(script)
def systemd_pg_service(todo):
pg_conf_dir = conf.get('main', 'pg_conf_dir')
for version in os.listdir(pg_conf_dir):
conf_dir = os.path.join(pg_conf_dir, version)
for cluster in os.listdir(conf_dir):
cluster_dir = os.path.join(conf_dir, cluster)
pg_conf = os.path.join(cluster_dir, 'postgresql.conf')
if is_mirror(pg_conf):
continue
cmd = f'systemctl {todo} postgresql@{version}-{cluster}.service'
run(cmd)
def old_pg_service(todo):
pg_conf_dir = conf.get('main', 'pg_conf_dir')
for version in os.listdir(pg_conf_dir):
cmd = f'/etc/init.d/postgresql {todo} {version}'
run_cmd()
def pg_service(todo): def pg_service(todo):
var = 'pg_' + todo if is_systemd():
cmd = conf.get('main', var) systemd_pg_service(todo)
run(cmd) else:
old_pg_service(todo)
def pg_stop(): def pg_stop():
...@@ -87,7 +113,9 @@ def pg_port(conf_file): ...@@ -87,7 +113,9 @@ def pg_port(conf_file):
def is_mirror(pg_conf): def is_mirror(pg_conf):
r = Reader(pg_conf) r = Reader(pg_conf)
mirror_conf = os.path.join(r['data_directory'], 'recovery.conf') mirror_conf = os.path.join(r['data_directory'], 'recovery.conf')
return os.path.exists(mirror_conf) if os.path.exists(mirror_conf):
return True
return 'recovery_target_timeline' in r
# Pastikan database server hanya bisa diakses oleh user postgres secara local # Pastikan database server hanya bisa diakses oleh user postgres secara local
......
...@@ -17,3 +17,6 @@ class Reader: ...@@ -17,3 +17,6 @@ class Reader:
def __getitem__(self, key): def __getitem__(self, key):
return self.conf[key] return self.conf[key]
def __contains__(self, key):
return key in self.conf
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!