Skip to content

Commit

Permalink
Improve PostgreSQL init script
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Oct 29, 2023
1 parent caf1922 commit 353cfc2
Show file tree
Hide file tree
Showing 14 changed files with 122 additions and 104 deletions.
24 changes: 12 additions & 12 deletions specs/postgresql-10/SOURCES/postgresql.init
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# postgresql This is the init script for starting up the PostgreSQL
# server.
# postgresql This is the init script for starting up the PostgreSQL {{MAJOR_VERSION}}
# server.
#
# chkconfig: - 64 36
# description: PostgreSQL database server.
Expand Down Expand Up @@ -32,12 +32,12 @@ GROUP_NAME="{{GROUP_NAME}}"

short_name="pgsql"

kv[prog_name]="postgresql"
kv[prog_name]="postgresql-${PKG_VERSION}"

kv.readSysconfig "${kv[prog_name]}-${MAJOR_VERSION}"
kv.readSysconfig "postgresql-${MAJOR_VERSION}"

kv[lock_file]="${kv[lock_dir]}/${kv[prog_name]}${PKG_VERSION}"
kv[pid_file]="${kv[pid_dir]}/${kv[prog_name]}${PKG_VERSION}.pid"
kv[lock_file]="${kv[lock_dir]}/${kv[prog_name]}"
kv[pid_file]="${kv[pid_dir]}/${kv[prog_name]}.pid"

pg_engine="${PG_ENGINE:-/usr/${short_name}-${MAJOR_VERSION}/bin}"
pg_postmaster="${PG_POSTMASTER:-${pg_engine}/postmaster}"
Expand Down Expand Up @@ -153,8 +153,8 @@ upgrade() {

local cur_version="${1-$MAJOR_VERSION}"
local prev_version="${2-$PREV_VERSION}"
local cur_init="${kv[prog_name]}-$cur_version"
local prev_init="${kv[prog_name]}-$prev_version"
local cur_init="postgresql-$cur_version"
local prev_init="postgresql-$prev_version"

if [[ ! -f "$INIT_DIR/$cur_init" ]] ; then
kv.error "Couldn't find init script $INIT_DIR/$cur_init" $ACTION_ERROR
Expand All @@ -171,10 +171,10 @@ upgrade() {
return $ACTION_ERROR
fi

local old_data=$(sed -n 's/^PGDATA=//p' "$INIT_DIR/${kv[prog_name]}-$cur_version")
local old_port=$(sed -n 's/^PGPORT=//p' "$INIT_DIR/${kv[prog_name]}-$prev_version")
local new_data=$(sed -n 's/^PGDATA=//p' "$INIT_DIR/${kv[prog_name]}-$cur_version")
local new_port=$(sed -n 's/^PGPORT=//p' "$INIT_DIR/${kv[prog_name]}-$prev_version")
local old_data=$(sed -n 's/^PGDATA=//p' "$INIT_DIR/postgresql-$cur_version")
local old_port=$(sed -n 's/^PGPORT=//p' "$INIT_DIR/postgresql-$prev_version")
local new_data=$(sed -n 's/^PGDATA=//p' "$INIT_DIR/postgresql-$cur_version")
local new_port=$(sed -n 's/^PGPORT=//p' "$INIT_DIR/postgresql-$prev_version")

/sbin/service "${PROG_NAME}${PKG_VERSION}" initdb

Expand Down
9 changes: 6 additions & 3 deletions specs/postgresql-10/postgresql-10.spec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

%define majorver 10
%define minorver 23
%define rel 0
%define rel 1
%define fullver %{majorver}.%{minorver}
%define pkgver 10
%define realname postgresql
Expand Down Expand Up @@ -141,7 +141,7 @@ PostgreSQL is an advanced Object-Relational database management system
(DBMS) that supports almost all SQL constructs (including
transactions, subselects and user-defined types and functions). The
postgresql package includes the client programs and libraries that
you'll need to access a PostgreSQL DBMS server. These PostgreSQL
you'll need to access a PostgreSQL DBMS server. These PostgreSQL
client programs are programs that directly manipulate the internal
structure of PostgreSQL databases on a PostgreSQL server. These client
programs can be located on the same machine with the PostgreSQL
Expand Down Expand Up @@ -499,7 +499,7 @@ sed -i 's/{{PREV_VERSION}}/%{prev_version}/g' %{buildroot}%{_unitdir}/postgresql
sed -i 's/{{USER_NAME}}/%{username}/g' %{buildroot}%{_unitdir}/postgresql-%{majorver}.service
sed -i 's/{{GROUP_NAME}}/%{groupname}/g' %{buildroot}%{_unitdir}/postgresql-%{majorver}.service

ln -sf %{_initddir}/%{service_name} %{buildroot}%{_initddir}/%{tinyname}%{majorver}
ln -sf %{service_name} %{buildroot}%{_initddir}/%{tinyname}%{majorver}

%if %pam
install -d %{buildroot}%{_sysconfdir}/pam.d
Expand Down Expand Up @@ -1080,6 +1080,9 @@ rm -rf %{buildroot}
################################################################################

%changelog
* Sun Oct 29 2023 Anton Novojilov <[email protected]> - 10.23-1
- Improved init script compatibility with systemd

* Thu Feb 09 2023 Anton Novojilov <[email protected]> - 10.23-0
- https://www.postgresql.org/docs/10/release-10-23.html

Expand Down
24 changes: 12 additions & 12 deletions specs/postgresql-11/SOURCES/postgresql.init
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# postgresql This is the init script for starting up the PostgreSQL
# server.
# postgresql This is the init script for starting up the PostgreSQL {{MAJOR_VERSION}}
# server.
#
# chkconfig: - 64 36
# description: PostgreSQL database server.
Expand Down Expand Up @@ -32,12 +32,12 @@ GROUP_NAME="{{GROUP_NAME}}"

short_name="pgsql"

kv[prog_name]="postgresql"
kv[prog_name]="postgresql-${PKG_VERSION}"

kv.readSysconfig "${kv[prog_name]}-${MAJOR_VERSION}"
kv.readSysconfig "postgresql-${MAJOR_VERSION}"

kv[lock_file]="${kv[lock_dir]}/${kv[prog_name]}${PKG_VERSION}"
kv[pid_file]="${kv[pid_dir]}/${kv[prog_name]}${PKG_VERSION}.pid"
kv[lock_file]="${kv[lock_dir]}/${kv[prog_name]}"
kv[pid_file]="${kv[pid_dir]}/${kv[prog_name]}.pid"

pg_engine="${PG_ENGINE:-/usr/${short_name}-${MAJOR_VERSION}/bin}"
pg_postmaster="${PG_POSTMASTER:-${pg_engine}/postmaster}"
Expand Down Expand Up @@ -153,8 +153,8 @@ upgrade() {

local cur_version="${1-$MAJOR_VERSION}"
local prev_version="${2-$PREV_VERSION}"
local cur_init="${kv[prog_name]}-$cur_version"
local prev_init="${kv[prog_name]}-$prev_version"
local cur_init="postgresql-$cur_version"
local prev_init="postgresql-$prev_version"

if [[ ! -f "$INIT_DIR/$cur_init" ]] ; then
kv.error "Couldn't find init script $INIT_DIR/$cur_init" $ACTION_ERROR
Expand All @@ -171,10 +171,10 @@ upgrade() {
return $ACTION_ERROR
fi

local old_data=$(sed -n 's/^PGDATA=//p' "$INIT_DIR/${kv[prog_name]}-$cur_version")
local old_port=$(sed -n 's/^PGPORT=//p' "$INIT_DIR/${kv[prog_name]}-$prev_version")
local new_data=$(sed -n 's/^PGDATA=//p' "$INIT_DIR/${kv[prog_name]}-$cur_version")
local new_port=$(sed -n 's/^PGPORT=//p' "$INIT_DIR/${kv[prog_name]}-$prev_version")
local old_data=$(sed -n 's/^PGDATA=//p' "$INIT_DIR/postgresql-$cur_version")
local old_port=$(sed -n 's/^PGPORT=//p' "$INIT_DIR/postgresql-$prev_version")
local new_data=$(sed -n 's/^PGDATA=//p' "$INIT_DIR/postgresql-$cur_version")
local new_port=$(sed -n 's/^PGPORT=//p' "$INIT_DIR/postgresql-$prev_version")

/sbin/service "${PROG_NAME}${PKG_VERSION}" initdb

Expand Down
9 changes: 6 additions & 3 deletions specs/postgresql-11/postgresql-11.spec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

%define majorver 11
%define minorver 21
%define rel 0
%define rel 1
%define fullver %{majorver}.%{minorver}
%define pkgver 11
%define realname postgresql
Expand Down Expand Up @@ -151,7 +151,7 @@ PostgreSQL is an advanced Object-Relational database management system
(DBMS) that supports almost all SQL constructs (including
transactions, subselects and user-defined types and functions). The
postgresql package includes the client programs and libraries that
you'll need to access a PostgreSQL DBMS server. These PostgreSQL
you'll need to access a PostgreSQL DBMS server. These PostgreSQL
client programs are programs that directly manipulate the internal
structure of PostgreSQL databases on a PostgreSQL server. These client
programs can be located on the same machine with the PostgreSQL
Expand Down Expand Up @@ -548,7 +548,7 @@ sed -i 's/{{PREV_VERSION}}/%{prev_version}/g' %{buildroot}%{_unitdir}/postgresql
sed -i 's/{{USER_NAME}}/%{username}/g' %{buildroot}%{_unitdir}/postgresql-%{majorver}.service
sed -i 's/{{GROUP_NAME}}/%{groupname}/g' %{buildroot}%{_unitdir}/postgresql-%{majorver}.service

ln -sf %{_initddir}/%{service_name} %{buildroot}%{_initddir}/%{tinyname}%{majorver}
ln -sf %{service_name} %{buildroot}%{_initddir}/%{tinyname}%{majorver}

%if %pam
install -d %{buildroot}%{_sysconfdir}/pam.d
Expand Down Expand Up @@ -1145,6 +1145,9 @@ rm -rf %{buildroot}
################################################################################

%changelog
* Sun Oct 29 2023 Anton Novojilov <[email protected]> - 11.21-1
- Improved init script compatibility with systemd

* Wed Sep 20 2023 Anton Novojilov <[email protected]> - 11.21-0
- https://www.postgresql.org/docs/11/release-11-21.html

Expand Down
24 changes: 12 additions & 12 deletions specs/postgresql-12/SOURCES/postgresql.init
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# postgresql This is the init script for starting up the PostgreSQL
# server.
# postgresql This is the init script for starting up the PostgreSQL {{MAJOR_VERSION}}
# server.
#
# chkconfig: - 64 36
# description: PostgreSQL database server.
Expand Down Expand Up @@ -32,12 +32,12 @@ GROUP_NAME="{{GROUP_NAME}}"

short_name="pgsql"

kv[prog_name]="postgresql"
kv[prog_name]="postgresql-${PKG_VERSION}"

kv.readSysconfig "${kv[prog_name]}-${MAJOR_VERSION}"
kv.readSysconfig "postgresql-${MAJOR_VERSION}"

kv[lock_file]="${kv[lock_dir]}/${kv[prog_name]}${PKG_VERSION}"
kv[pid_file]="${kv[pid_dir]}/${kv[prog_name]}${PKG_VERSION}.pid"
kv[lock_file]="${kv[lock_dir]}/${kv[prog_name]}"
kv[pid_file]="${kv[pid_dir]}/${kv[prog_name]}.pid"

pg_engine="${PG_ENGINE:-/usr/${short_name}-${MAJOR_VERSION}/bin}"
pg_postmaster="${PG_POSTMASTER:-${pg_engine}/postmaster}"
Expand Down Expand Up @@ -153,8 +153,8 @@ upgrade() {

local cur_version="${1-$MAJOR_VERSION}"
local prev_version="${2-$PREV_VERSION}"
local cur_init="${kv[prog_name]}-$cur_version"
local prev_init="${kv[prog_name]}-$prev_version"
local cur_init="postgresql-$cur_version"
local prev_init="postgresql-$prev_version"

if [[ ! -f "$INIT_DIR/$cur_init" ]] ; then
kv.error "Couldn't find init script $INIT_DIR/$cur_init" $ACTION_ERROR
Expand All @@ -171,10 +171,10 @@ upgrade() {
return $ACTION_ERROR
fi

local old_data=$(sed -n 's/^PGDATA=//p' "$INIT_DIR/${kv[prog_name]}-$cur_version")
local old_port=$(sed -n 's/^PGPORT=//p' "$INIT_DIR/${kv[prog_name]}-$prev_version")
local new_data=$(sed -n 's/^PGDATA=//p' "$INIT_DIR/${kv[prog_name]}-$cur_version")
local new_port=$(sed -n 's/^PGPORT=//p' "$INIT_DIR/${kv[prog_name]}-$prev_version")
local old_data=$(sed -n 's/^PGDATA=//p' "$INIT_DIR/postgresql-$cur_version")
local old_port=$(sed -n 's/^PGPORT=//p' "$INIT_DIR/postgresql-$prev_version")
local new_data=$(sed -n 's/^PGDATA=//p' "$INIT_DIR/postgresql-$cur_version")
local new_port=$(sed -n 's/^PGPORT=//p' "$INIT_DIR/postgresql-$prev_version")

/sbin/service "${PROG_NAME}${PKG_VERSION}" initdb

Expand Down
9 changes: 6 additions & 3 deletions specs/postgresql-12/postgresql-12.spec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

%define majorver 12
%define minorver 16
%define rel 0
%define rel 1
%define fullver %{majorver}.%{minorver}
%define pkgver 12
%define realname postgresql
Expand Down Expand Up @@ -151,7 +151,7 @@ PostgreSQL is an advanced Object-Relational database management system
(DBMS) that supports almost all SQL constructs (including
transactions, subselects and user-defined types and functions). The
postgresql package includes the client programs and libraries that
you'll need to access a PostgreSQL DBMS server. These PostgreSQL
you'll need to access a PostgreSQL DBMS server. These PostgreSQL
client programs are programs that directly manipulate the internal
structure of PostgreSQL databases on a PostgreSQL server. These client
programs can be located on the same machine with the PostgreSQL
Expand Down Expand Up @@ -550,7 +550,7 @@ sed -i 's/{{PREV_VERSION}}/%{prev_version}/g' %{buildroot}%{_unitdir}/postgresql
sed -i 's/{{USER_NAME}}/%{username}/g' %{buildroot}%{_unitdir}/postgresql-%{majorver}.service
sed -i 's/{{GROUP_NAME}}/%{groupname}/g' %{buildroot}%{_unitdir}/postgresql-%{majorver}.service

ln -sf %{_initddir}/%{service_name} %{buildroot}%{_initddir}/%{tinyname}%{majorver}
ln -sf %{service_name} %{buildroot}%{_initddir}/%{tinyname}%{majorver}

%if %pam
install -d %{buildroot}%{_sysconfdir}/pam.d
Expand Down Expand Up @@ -1147,6 +1147,9 @@ rm -rf %{buildroot}
################################################################################

%changelog
* Sun Oct 29 2023 Anton Novojilov <[email protected]> - 12.16-1
- Improved init script compatibility with systemd

* Wed Sep 20 2023 Anton Novojilov <[email protected]> - 12.16-0
- https://www.postgresql.org/docs/12/release-12-16.html

Expand Down
24 changes: 12 additions & 12 deletions specs/postgresql-13/SOURCES/postgresql.init
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# postgresql This is the init script for starting up the PostgreSQL
# server.
# postgresql This is the init script for starting up the PostgreSQL {{MAJOR_VERSION}}
# server.
#
# chkconfig: - 64 36
# description: PostgreSQL database server.
Expand Down Expand Up @@ -32,12 +32,12 @@ GROUP_NAME="{{GROUP_NAME}}"

short_name="pgsql"

kv[prog_name]="postgresql"
kv[prog_name]="postgresql-${PKG_VERSION}"

kv.readSysconfig "${kv[prog_name]}-${MAJOR_VERSION}"
kv.readSysconfig "postgresql-${MAJOR_VERSION}"

kv[lock_file]="${kv[lock_dir]}/${kv[prog_name]}${PKG_VERSION}"
kv[pid_file]="${kv[pid_dir]}/${kv[prog_name]}${PKG_VERSION}.pid"
kv[lock_file]="${kv[lock_dir]}/${kv[prog_name]}"
kv[pid_file]="${kv[pid_dir]}/${kv[prog_name]}.pid"

pg_engine="${PG_ENGINE:-/usr/${short_name}-${MAJOR_VERSION}/bin}"
pg_postmaster="${PG_POSTMASTER:-${pg_engine}/postmaster}"
Expand Down Expand Up @@ -153,8 +153,8 @@ upgrade() {

local cur_version="${1-$MAJOR_VERSION}"
local prev_version="${2-$PREV_VERSION}"
local cur_init="${kv[prog_name]}-$cur_version"
local prev_init="${kv[prog_name]}-$prev_version"
local cur_init="postgresql-$cur_version"
local prev_init="postgresql-$prev_version"

if [[ ! -f "$INIT_DIR/$cur_init" ]] ; then
kv.error "Couldn't find init script $INIT_DIR/$cur_init" $ACTION_ERROR
Expand All @@ -171,10 +171,10 @@ upgrade() {
return $ACTION_ERROR
fi

local old_data=$(sed -n 's/^PGDATA=//p' "$INIT_DIR/${kv[prog_name]}-$cur_version")
local old_port=$(sed -n 's/^PGPORT=//p' "$INIT_DIR/${kv[prog_name]}-$prev_version")
local new_data=$(sed -n 's/^PGDATA=//p' "$INIT_DIR/${kv[prog_name]}-$cur_version")
local new_port=$(sed -n 's/^PGPORT=//p' "$INIT_DIR/${kv[prog_name]}-$prev_version")
local old_data=$(sed -n 's/^PGDATA=//p' "$INIT_DIR/postgresql-$cur_version")
local old_port=$(sed -n 's/^PGPORT=//p' "$INIT_DIR/postgresql-$prev_version")
local new_data=$(sed -n 's/^PGDATA=//p' "$INIT_DIR/postgresql-$cur_version")
local new_port=$(sed -n 's/^PGPORT=//p' "$INIT_DIR/postgresql-$prev_version")

/sbin/service "${PROG_NAME}${PKG_VERSION}" initdb

Expand Down
9 changes: 6 additions & 3 deletions specs/postgresql-13/postgresql-13.spec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

%define majorver 13
%define minorver 12
%define rel 0
%define rel 1
%define fullver %{majorver}.%{minorver}
%define pkgver 13
%define realname postgresql
Expand Down Expand Up @@ -151,7 +151,7 @@ PostgreSQL is an advanced Object-Relational database management system
(DBMS) that supports almost all SQL constructs (including
transactions, subselects and user-defined types and functions). The
postgresql package includes the client programs and libraries that
you'll need to access a PostgreSQL DBMS server. These PostgreSQL
you'll need to access a PostgreSQL DBMS server. These PostgreSQL
client programs are programs that directly manipulate the internal
structure of PostgreSQL databases on a PostgreSQL server. These client
programs can be located on the same machine with the PostgreSQL
Expand Down Expand Up @@ -550,7 +550,7 @@ sed -i 's/{{PREV_VERSION}}/%{prev_version}/g' %{buildroot}%{_unitdir}/postgresql
sed -i 's/{{USER_NAME}}/%{username}/g' %{buildroot}%{_unitdir}/postgresql-%{majorver}.service
sed -i 's/{{GROUP_NAME}}/%{groupname}/g' %{buildroot}%{_unitdir}/postgresql-%{majorver}.service

ln -sf %{_initddir}/%{service_name} %{buildroot}%{_initddir}/%{tinyname}%{majorver}
ln -sf %{service_name} %{buildroot}%{_initddir}/%{tinyname}%{majorver}

%if %pam
install -d %{buildroot}%{_sysconfdir}/pam.d
Expand Down Expand Up @@ -1150,6 +1150,9 @@ rm -rf %{buildroot}
################################################################################

%changelog
* Sun Oct 29 2023 Anton Novojilov <[email protected]> - 13.12-1
- Improved init script compatibility with systemd

* Wed Sep 20 2023 Anton Novojilov <[email protected]> - 13.12-0
- https://www.postgresql.org/docs/13/release-13-12.html

Expand Down
Loading

0 comments on commit 353cfc2

Please sign in to comment.