Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2026-06-19 0cfc87bd32822e5ba22d8c2b1a26fa60f63ad7fa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#!/bin/bash
 
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
  echo "Ошибка: Необходимо указать переменные: RUDB_PATH, RUDB_DB_PATH и LOG_PATH."
  echo "Использование: $0 <путь_к_RUDB_PATH> <путь_к_RUDB_DB_PATH> <путь_к_LOG_PATH>"
  exit 1
fi
 
MAJOR_VERSION="18"
RUDB_VERSION="18"
 
RUDB_PATH="$1"
RUDB_DB_PATH="$2"
LOG_PATH="$3"
RUDB_SERVICE="${4:-rudb-18.service}"
 
echo "PATHS: $RUDB_PATH, $RUDB_DB_PATH, $LOG_PATH, $RUDB_SERVICE"
 
data=$(cat <<'EOF'
 
=== Содержимое файла: rudb.spec ===
%global __brp_check_rpaths %{nil}
%global __brp_check_rpaths_relocatable %{nil}
%global __brp_python_hardlink %{nil}
%global _build_id_links none
%define msk_date %(TZ='Europe/Moscow' date +%%y%%m%%d)
Name:           rudb-<MAJOR_VERSION>
Version:        <RUDB_VERSION>.%{msk_date}01
Release:        1%{?dist}
Summary:        RuDB Database Management System <RUDB_VERSION>
Group:          Databases
License:        proprietary
URL:            https://database.ru/
BuildArch:      x86_64
Requires:       systemd
Requires(pre):  shadow-utils
Requires:       libpq5
Requires:       libgeos
Requires:       libproj
Requires:       libprotobuf-c1
Source1:                <RUDB_SERVICE>
BuildRoot:              %{_tmppath}/%{name}-%{version}-root
 
%define debug_package %{nil}
%define __strip /bin/true
%define __os_install_post %{nil}
 
%description
Build of RuDB Management System installed in <RUDB_PATH>.
 
%prep
 
%build
 
%install
export QA_RPATHS=0x000B
 
# Очистка путей перед копированием
rm -rf "%{buildroot}<RUDB_PATH>/bin" 2>/dev/null
rm -rf "%{buildroot}<RUDB_PATH>/include" 2>/dev/null
rm -rf "%{buildroot}<RUDB_PATH>/lib" 2>/dev/null
rm -rf "%{buildroot}<RUDB_PATH>/share" 2>/dev/null
 
mkdir -p %{buildroot}<RUDB_PATH>
cp -a ~/rudb_bin<RUDB_PATH>/* %{buildroot}<RUDB_PATH>/
cp ~/rudb_bin/rudb_data1.tar.gz %{buildroot}<RUDB_PATH>/
 
mkdir -p %{buildroot}/etc/ld.so.conf.d/
echo "<RUDB_PATH>/lib" > %{buildroot}/etc/ld.so.conf.d/rudb.conf
 
# Устанавливаем systemd юниты
mkdir -p %{buildroot}/etc/systemd/system
install -m 644 %{_sourcedir}/<RUDB_SERVICE> %{buildroot}/etc/systemd/system/
install -m 644 %{_sourcedir}/dgrid.service %{buildroot}/etc/systemd/system/
install -m 644 %{_sourcedir}/dgridd.conf  %{buildroot}/etc/
 
%post
set -e
 
CREATE_DB=true
if [ -d "<RUDB_DATA>" ]; then
    CREATE_DB=false
fi
 
if ! id "postgres" >/dev/null 2>&1; then
    useradd --system --user-group --create-home --home-dir /home/postgres --shell /bin/bash postgres
    echo "postgres:postgres" | chpasswd
fi
 
if [ ! -d "<RUDB_PATH>" ]; then
    mkdir -p <RUDB_PATH>
fi
 
DGRID_LOG_PATH='/var/log/dgrid/'
if [ ! -d "$DGRID_LOG_PATH" ]; then
    mkdir -p $DGRID_LOG_PATH
fi
 
# Нативные симлинки PostgreSQL
declare -A LINKS=(
    ["pg_ctl"]="pg_ctl"
    ["initdb"]="initdb"
    ["clusterdb"]="clusterdb"
    ["createdb"]="createdb"
    ["dropdb"]="dropdb"
    ["reindexdb"]="reindexdb"
    ["vacuumdb"]="vacuumdb"
    ["vacuumlo"]="vacuumlo"
    ["createuser"]="createuser"
    ["dropuser"]="dropuser"
    ["psql"]="psql"
    ["pg_isready"]="pg_isready"
    ["pgbench"]="pgbench"
    ["pg_dump"]="pg_dump"
    ["pg_dumpall"]="pg_dumpall"
    ["pg_restore"]="pg_restore"
    ["pg_basebackup"]="pg_basebackup"
    ["pg_combinebackup"]="pg_combinebackup"
    ["pg_verifybackup"]="pg_verifybackup"
    ["pg_receivewal"]="pg_receivewal"
    ["pg_recvlogical"]="pg_recvlogical"
    ["pg_resetwal"]="pg_resetwal"
    ["pg_rewind"]="pg_rewind"
    ["pg_waldump"]="pg_waldump"
    ["pg_walsummary"]="pg_walsummary"
    ["pg_amcheck"]="pg_amcheck"
    ["pg_checksums"]="pg_checksums"
    ["pg_controldata"]="pg_controldata"
    ["pg_upgrade"]="pg_upgrade"
    ["pg_test_fsync"]="pg_test_fsync"
    ["pg_test_timing"]="pg_test_timing"
    ["ecpg"]="ecpg"
    ["oid2name"]="oid2name"
)
 
BIN_PATH="<RUDB_PATH>/bin"
LINK_PATH="/usr/bin"
 
for src in "${!LINKS[@]}"; do
    target="${LINKS[$src]}"
    rm -f "${LINK_PATH}/${target}"
    ln -s "${BIN_PATH}/${src}" "${LINK_PATH}/${target}"
done
 
/sbin/ldconfig
 
# ВАЖНО: Перезагрузка демонов systemd ДО того, как мы будем обращаться к новым сервисам
systemctl daemon-reload || true
 
systemctl stop <RUDB_SERVICE> || true
systemctl stop dgrid.service || true
sleep 1
systemctl disable <RUDB_SERVICE> || true
systemctl disable dgrid.service || true
sleep 1
 
if $CREATE_DB; then
    rm -rf <RUDB_DATA>
    mkdir -p <RUDB_DATA>
    tar -xzf <RUDB_PATH>/rudb_data1.tar.gz -C <RUDB_DATA>
    chown -R postgres:postgres <RUDB_DATA>
fi
 
systemctl enable <RUDB_SERVICE> || true
systemctl enable dgrid.service || true
sleep 1
 
# ВАЖНО: Добавлено '|| true', чтобы ошибка старта не приводила к поломке пакетного менеджера.
# В случае проблемы с базой администратор сможет посмотреть логи через journalctl.
systemctl start <RUDB_SERVICE> || true
systemctl start dgrid.service || true
 
%preun
if [ "$1" = 0 ]; then
    systemctl disable <RUDB_SERVICE> || true
    systemctl disable dgrid.service || true
    systemctl stop <RUDB_SERVICE> || true
    systemctl stop dgrid.service || true
    sleep 1
    systemctl daemon-reload || true
fi
 
# Удаление симлинков
rm -f /usr/bin/pg_ctl
rm -f /usr/bin/initdb
rm -f /usr/bin/clusterdb
rm -f /usr/bin/createdb
rm -f /usr/bin/dropdb
rm -f /usr/bin/reindexdb
rm -f /usr/bin/vacuumdb
rm -f /usr/bin/vacuumlo
rm -f /usr/bin/createuser
rm -f /usr/bin/dropuser
rm -f /usr/bin/psql
rm -f /usr/bin/pg_isready
rm -f /usr/bin/pgbench
rm -f /usr/bin/pg_dump
rm -f /usr/bin/pg_dumpall
rm -f /usr/bin/pg_restore
rm -f /usr/bin/pg_basebackup
rm -f /usr/bin/pg_combinebackup
rm -f /usr/bin/pg_verifybackup
rm -f /usr/bin/pg_receivewal
rm -f /usr/bin/pg_recvlogical
rm -f /usr/bin/pg_resetwal
rm -f /usr/bin/pg_rewind
rm -f /usr/bin/pg_waldump
rm -f /usr/bin/pg_walsummary
rm -f /usr/bin/pg_amcheck
rm -f /usr/bin/pg_checksums
rm -f /usr/bin/pg_controldata
rm -f /usr/bin/pg_upgrade
rm -f /usr/bin/pg_test_fsync
rm -f /usr/bin/pg_test_timing
rm -f /usr/bin/ecpg
rm -f /usr/bin/oid2name
 
%files
<RUDB_PATH>
/etc/systemd/system/<RUDB_SERVICE>
/etc/systemd/system/dgrid.service
/etc/ld.so.conf.d/rudb.conf
/etc/dgridd.conf
 
%changelog
* Tue Dec 17 2024 Association of DBMS Vendors <info@database.ru> - 1.0-1
- Initial RPM package for RUDB build.
EOF
)
 
# Обработка текста и создание файла rudb.spec
current_file=""
echo "$data" | while IFS= read -r line; do
  if [[ "$line" =~ ^===\ Содержимое\ файла:\ (.+)\ ===$ ]]; then
    current_file="${BASH_REMATCH[1]}"
    > "$current_file"
    echo "Создан файл: $current_file"
  elif [[ -n "$current_file" ]]; then
    # Исключение bash-переменных из замены
    if [[ "$line" =~ \$\{.*\} ]]; then
      echo "$line" >> "$current_file"
      continue
    fi
 
    modified_line=$(echo "$line" | sed "s|<RUDB_DATA>|$RUDB_DB_PATH|g")
    # Используем единую переменную без двойных слешей
    modified_line=$(echo "$modified_line" | sed "s|<RUDB_PATH>|$RUDB_PATH|g")
    modified_line=$(echo "$modified_line" | sed "s|<RUDB_LOG_PATH>|$LOG_PATH|g")
    modified_line=$(echo "$modified_line" | sed "s|<RUDB_SERVICE>|$RUDB_SERVICE|g")
    modified_line=$(echo "$modified_line" | sed "s|<RUDB_VERSION>|$RUDB_VERSION|g")
    modified_line=$(echo "$modified_line" | sed "s|<MAJOR_VERSION>|$MAJOR_VERSION|g")
 
    echo "$modified_line" >> "$current_file"
  fi
done
 
echo "Обработка завершена. .SPEC файл создан."