Repair monitor cluster upgrade without blocking K1 package configuration

This commit is contained in:
DCCONSTRUCTIONS
2026-09-08 10:44:27 +03:00
parent 6492ebcdee
commit 14f8375713
11 changed files with 160 additions and 21 deletions
+18 -7
View File
@@ -9,11 +9,22 @@ install -d -m 0750 -o mission-core-monitor -g mission-core-node /var/lib/mission
install -d -m 0755 -o postgres -g postgres /run/mission-core-monitor-db
install -d -m 0755 /etc/tmpfiles.d
printf '%s\n' 'd /run/mission-core-monitor-db 0755 postgres postgres -' > /etc/tmpfiles.d/mission-core-monitor.conf
if [ ! -d /etc/postgresql/16/ndc-monitor ]; then
pg_createcluster 16 ndc-monitor --port=5433 --socketdir=/run/mission-core-monitor-db --datadir=/var/lib/mission-core-monitor-db --start-conf=auto -- --auth-local=peer --auth-host=reject
# R18 used a dash, which the PostgreSQL systemd template expands as a slash.
# Rename only our exact cluster. pg_renamecluster preserves this custom data
# directory, updates its configuration paths, and retains all database files.
if [ -d /etc/postgresql/16/ndc-monitor ]; then
test ! -d /etc/postgresql/16/ndcmonitor
test "$(pg_conftool -s 16 ndc-monitor show data_directory)" = /var/lib/mission-core-monitor-db
test "$(pg_conftool -s 16 ndc-monitor show port)" = 5433
pg_renamecluster 16 ndc-monitor ndcmonitor
fi
install -d -m 0755 /etc/postgresql/16/ndc-monitor/conf.d
cat > /etc/postgresql/16/ndc-monitor/conf.d/60-mission-core-monitor.conf <<'CONF'
if [ ! -d /etc/postgresql/16/ndcmonitor ]; then
pg_createcluster 16 ndcmonitor --port=5433 --socketdir=/run/mission-core-monitor-db --datadir=/var/lib/mission-core-monitor-db --start-conf=auto -- --auth-local=peer --auth-host=reject
fi
test "$(pg_conftool -s 16 ndcmonitor show data_directory)" = /var/lib/mission-core-monitor-db
test "$(pg_conftool -s 16 ndcmonitor show port)" = 5433
install -d -m 0755 /etc/postgresql/16/ndcmonitor/conf.d
cat > /etc/postgresql/16/ndcmonitor/conf.d/60-mission-core-monitor.conf <<'CONF'
listen_addresses = ''
unix_socket_directories = '/run/mission-core-monitor-db'
shared_preload_libraries = 'timescaledb'
@@ -32,8 +43,8 @@ statement_timeout = '5s'
log_statement = 'none'
log_min_error_statement = 'panic'
CONF
install -d -m 0755 /etc/systemd/system/postgresql@16-ndc-monitor.service.d
cat > /etc/systemd/system/postgresql@16-ndc-monitor.service.d/60-mission-core-monitor.conf <<'CONF'
install -d -m 0755 /etc/systemd/system/postgresql@16-ndcmonitor.service.d
cat > /etc/systemd/system/postgresql@16-ndcmonitor.service.d/60-mission-core-monitor.conf <<'CONF'
[Service]
ExecStartPre=+/usr/bin/install -d -m 0755 -o postgres -g postgres /run/mission-core-monitor-db
MemoryHigh=256M
@@ -43,7 +54,7 @@ TasksMax=32
Nice=10
CONF
systemctl daemon-reload
systemctl restart postgresql@16-ndc-monitor.service
systemctl restart postgresql@16-ndcmonitor.service
runuser -u postgres -- psql -X -v ON_ERROR_STOP=1 -h /run/mission-core-monitor-db -p 5433 -d postgres <<'SQL'
SELECT 'CREATE ROLE "mission-core-monitor" LOGIN NOSUPERUSER NOCREATEDB NOCREATEROLE' WHERE NOT EXISTS(SELECT FROM pg_roles WHERE rolname='mission-core-monitor') \gexec
SELECT 'CREATE DATABASE mission_core_monitor OWNER "mission-core-monitor"' WHERE NOT EXISTS(SELECT FROM pg_database WHERE datname='mission_core_monitor') \gexec