Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
postgresql-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
PostgreSQL
postgresql-common
Commits
8a9f9c51
Commit
8a9f9c51
authored
20 years ago
by
Martin Pitt
Browse files
Options
Downloads
Patches
Plain Diff
reworked init.d-functions to provide per-version and per-cluster functions
parent
ab2fa6f0
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
postgresql-common-1/debian/init.d-functions
+70
-28
70 additions, 28 deletions
postgresql-common-1/debian/init.d-functions
with
70 additions
and
28 deletions
postgresql-common-1/debian/init.d-functions
+
70
−
28
View file @
8a9f9c51
...
...
@@ -3,17 +3,17 @@
# /etc/init.d/postgresqlX.Y.
# Make sure the log directory and file exist with the correct ownership
# needs correct $VERSION
# needs correct $VERSION
and $CLUSTER
assert_logfile() {
if [ -z "$VERSION" ]; then
echo
"
Error: assert_logfile called without proper \$VERSION" >&2
if [ -z "$VERSION"
-o -z "$CLUSTER"
]; then
echo
-e "\n
Error: assert_logfile called without proper \$VERSION
and \$CLUSTER
" >&2
exit 1
fi
LOGFILE=
${POSTGRES_LOG:-
/var/log/postgresql/postgresql-$VERSION.log
}
LOGDIR=
"`
dirname
\
"$LOGFILE
\"`
"
LOGFILE=
"
/var/log/postgresql/postgresql-$VERSION
-$CLUSTER
.log
"
LOGDIR=
$(
dirname "$LOGFILE"
)
[ -d "$LOGDIR" ] || install -d -m 77
0
-o
postgres
-g postgres "$LOGDIR"
[ -d "$LOGDIR" ] || install -d -m
2
77
5
-o
root
-g postgres "$LOGDIR"
if [ ! -e "$LOGFILE" ]; then
touch "$LOGFILE"
...
...
@@ -22,10 +22,10 @@ assert_logfile() {
fi
}
# Get $PGDATA path, $PG_VERSION, and $PG_CTL path from given
cluster name
($1) and
# check that the
#
cluster data exists.
# Get $PGDATA path, $PG_VERSION, and $PG_CTL path from given
version
($1) and
#
cluster name ($2) and
check that the cluster data exists.
prepare_cluster() {
PGDATA=/etc/postgresql/$1/pgdata
PGDATA=/etc/postgresql/$1/
$CLUSTER/
pgdata
if [ ! -d $PGDATA ]; then
echo "Error: symbolic link $PGDATA to data directory does not exist, exiting" >&2
exit 1
...
...
@@ -37,13 +37,19 @@ prepare_cluster() {
fi
PG_VERSION=$(< $PGDATA/PG_VERSION)
if [ "$1" != $PG_VERSION ]; then
echo "Error: $PGDATA/PG_VERSION is $PG_VERSION, but configuration directory is for version $1)" >&2
exit 1
fi
PG_CTL=/usr/lib/postgresql/$PG_VERSION/bin/pg_ctl
}
# start given cluster
start() {
echo -n "Starting PostgreSQL database $1 server: postmaster"
prepare_cluster $1
# start cluster $2 of version $1
# output is appropriate after "Starting ...:" init message
start_ver_cluster() {
prepare_cluster $1 $2
echo -n " $2"
assert_logfile
ERRMSG=$(/sbin/start-stop-daemon --pidfile $PGDATA/postmaster.pid \
...
...
@@ -57,13 +63,13 @@ start() {
fi
[ "$ERRMSG" ] && echo -n "($ERRMSG)" >&2 || true
echo "."
}
# stop given cluster (i. e. major version)
stop() {
echo -n "Stopping PostgreSQL database $1 server: postmaster"
prepare_cluster $1
# stop cluster $2 of version $1
# output is appropriate after "Stopping ...:" init message
stop_ver_cluster() {
prepare_cluster $1 $2
echo -n " $2"
start-stop-daemon -c postgres --start --exec $PG_CTL -- -D "$PGDATA" stop -s -w -m fast
...
...
@@ -82,13 +88,13 @@ stop() {
rm -f "$PGDATA/postmaster.pid"
fi
fi
echo "."
}
# reload given cluster
reload() {
echo -n "Reloading PostgreSQL database $1 server: postmaster"
prepare_cluster $1
# reload cluster $2 of version $1
# output is appropriate after "Reloading ...:" init message
reload_ver_cluster() {
prepare_cluster $1 $2
echo -n " $2"
ERRMSG=$(start-stop-daemon --chuid postgres --start \
--exec $PG_CTL -- -D $PGDATA -s reload)
...
...
@@ -100,14 +106,50 @@ reload() {
fi
[ "$ERRMSG" ] && echo -n " ($ERRMSG)" >&2 || true
echo "."
}
# print status
for given cluster
status() {
prepare_cluster $1
# print status
of cluster $2 of version $1
status
_ver_cluster
() {
prepare_cluster $1
$2
echo "--
Cluster $1 --
"
echo "--
Status of cluster $PG_VERSION/$CLUSTER:
"
start-stop-daemon --chuid postgres --start --exec $PG_CTL -- -D $PGDATA status
}
# do command/function $1 to all clusters of version $2 with command
# description $3; output according to Debian Policy for init scripts
do_op_all() {
[ "$1" ] || { echo "Error: invalid command '$1'" >&2; exit 1; }
[ "$2" -a -d "/etc/postgresql/$2" ] || { echo "Error: invalid version '$2'" >&2; exit 1; }
[ -z "$3" ] || echo -n "$3 PostgreSQL $2 database server:"
for c in /etc/postgresql/"$2"/*; do
$1 $2 $(basename $c)
done
[ -z "$3" ] || echo "."
}
# start all clusters of version $1
# output according to Debian Policy for init scripts
start() {
do_op_all start_ver_cluster $1 "Starting"
}
# stop all clusters of version $1
# output according to Debian Policy for init scripts
stop() {
do_op_all stop_ver_cluster $1 "Stopping"
}
# reload all clusters of version $1
# output according to Debian Policy for init scripts
reload() {
do_op_all reload_ver_cluster $1 "Reloading"
}
# display status all clusters of version $1
status() {
do_op_all status_ver_cluster $1
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment