![]() Server : Apache System : Linux server2.thebrownbagmedia.com 4.18.0-553.34.1.el8_10.x86_64 #1 SMP Wed Jan 8 09:40:06 EST 2025 x86_64 User : topnotchcv ( 1029) PHP Version : 8.1.32 Disable Function : NONE Directory : /sbin/ |
#! /bin/bash # Automatically create systemd unit for PostgreSQL service. set -e . "/usr/share/postgresql-setup/library.sh" USAGE_STRING=$"\ Usage: $0 --unit SYSTEMD_UNIT --datadir DATADIR Automatically create systemd unit for PostgreSQL service. For more info and howto/when use this script please look at the documentation file /usr/share/doc/postgresql/README.rpm-dist. Options: --unit=UNIT_NAME The name of new systemdunit, of form postgresql@<string>, will generate service file postgresql@<string>.service. --datadir=DATADIR Where the data will be stored. The postgres user needs to have permissions to create this directory. " root_prereq opt_unit=default opt_datadir=default test $# -ne 0 || { echo >&2 "$USAGE_STRING" exit 1 } args=$(getopt -o "" -l "datadir:,unit:,help,version" -n "$0" -- "$@") || exit 1 eval set -- "$args" while true; do case "$1" in --datadir|--unit) opt=${1##--} opt=${opt##-} opt=${opt//-/_} eval "opt_$opt=\$2" shift 2 ;; --help) echo "$USAGE_STRING" exit 0 ;; --version) echo "postgresql-new-systemd-unit 8.7" echo $"Built against PostgreSQL version 10.23." exit 0 ;; --) # end! shift break ;; *) echo "programmer mistake ($1)" >&2 exit 1 ;; esac done required_ok=: for opt in unit datadir; do if eval "test \"\$opt_$opt\" == default"; then required_ok=false error "option --$opt required" fi done $required_ok || die "missing argument" case $opt_unit in *.service) opt_unit=${opt_unit%%.service} ;; esac case $opt_unit in postgresql@*) ;; *) die "the --unit needs to start with 'postgresql@', e.g. 'postgresql@second'" ;; esac exit_handler() { test -z "$cleanup_dropin" || { info "cleaning up created dropin directory" eval "$cleanup_dropin" } } cleanup_dropin= trap exit_handler 0 dropindir="/etc/systemd/system/$opt_unit.service.d" dropin="$dropindir/30-postgresql-setup.conf" test ! -e "$dropindir" \ || die "The systemd drop-in directory '$dropindir' already exists" mkdir -p "$dropindir" \ || die "Can not create '$dropindir'" cleanup_dropin="rm -rf \"$dropindir\"" generate_dropin () { cat <<EOF > "$1" [Service] Environment=PGDATA=$opt_datadir EOF } generate_dropin "$dropin" || die "Can not write to '$dropin'" reload_systemd="systemctl daemon-reload" $reload_systemd || die $"Can not perform '$reload_systemd'" parentdir=$(dirname "$opt_datadir") if ! /usr/sbin/runuser -s /bin/sh -l postgres -c "test -w $(printf %q "$parentdir")"; then error "The '$parentdir' directory doesn't exit or 'postgres' can not" error_q "write there. Please either fix the permissions or change the" error_q "configuration in dropin directory before trying again." exit 1 fi info $"The '$opt_unit.service' configured in '$dropindir' directory." cleanup_dropin=