<commit_before>#!/bin/sh
set -e

### BEGIN INIT INFO
# Provides:             postgresql
# Required-Start:       $local_fs $remote_fs $network $time
# Required-Stop:        $local_fs $remote_fs $network $time
# Should-Start:         $syslog
# Should-Stop:          $syslog
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    PostgreSQL RDBMS server
### END INIT INFO

# Setting environment variables for the postmaster here does not work; please
# set them in /etc/postgresql/<version>/<cluster>/environment instead.

[ -r /usr/share/postgresql-common/init.d-functions ] || exit 0

. /usr/share/postgresql-common/init.d-functions

# ORIGINAL version management disabled for Travis CI specific needs, see below
# versions can be specified explicitly
#if [ -n "$2" ]; then
#    versions="$2 $3 $4 $5 $6 $7 $8 $9"
#else
#    get_versions
#fi

# there should be only one running instance, and we must act in consequence...
running_version=$(pg_lsclusters -h | grep online | awk '{print $1}')

if [ -n "$2" ]; then
    versions="$2"
elif [ -n "$1" ] && [ $1 = 'stop' ]; then
    # be 100% sure to stop all instances (robustness hack)
    get_versions
elif [ -n "$running_version"  ]; then
    versions="$running_version"
else
    versions="<%= node['postgresql']['default_version'] %>"
fi

if [ -n "$1" ] && [ $1 != 'stop' ] && [ $1 != 'status' ]; then
    if [ -n "$running_version" ] && [ "$versions" != "$running_version" ]; then
        echo "Refused to $1 PostgreSQL $versions, because PostgreSQL $running_version is currently running! You should first stop $running_version instance..."
        exit 13
    fi
    if [ ! -d "/etc/postgresql/$versions" ]; then
        echo "PostgreSQL $versions is not installed!"
        exit 31
    fi
fi

<% if node['postgresql']['data_on_ramfs'] %>
# Copy initial databases to RAMFS
for data_dir in /var/lib/postgresql/*; do
    v=$(basename $data_dir)
    if [ -d $(dirname <%= node['postgresql']['data_dir'] %>) -a ! -d <%= node['postgresql']['data_dir'] %>/$v ]; then
        mkdir -p <%= node['postgresql']['data_dir'] %>/$v
        cp -rp $data_dir <%= node['postgresql']['data_dir'] %>/
    fi
done
<% end %>

case "$1" in
    start|stop|restart|reload)
        if [ -z "`pg_lsclusters -h`" ]; then
            log_warning_msg 'No PostgreSQL clusters exist; see "man pg_createcluster"'
            exit 0
        fi
        for v in $versions; do
            $1 $v || EXIT=$?
        done
        exit ${EXIT:-0}
        ;;
    status)
        LS=`pg_lsclusters -h`
        # no clusters -> unknown status
        [ -n "$LS" ] || exit 4
        echo "$LS" | awk 'BEGIN {rc=0} {if (match($4, "down")) rc=3; printf ("%s/%s (port %s): %s\n", $1, $2, $3, $4)}; END {exit rc}'
        ;;
    force-reload)
        for v in $versions; do
            reload $v
        done
        ;;
    *)
        echo "Usage: $0 {start|stop|restart|reload|force-reload|status} [version ..]"<commit_msg>PostgreSQL: fix a bug in init.d script<commit_after>#!/bin/sh
set -e

### BEGIN INIT INFO
# Provides:             postgresql
# Required-Start:       $local_fs $remote_fs $network $time
# Required-Stop:        $local_fs $remote_fs $network $time
# Should-Start:         $syslog
# Should-Stop:          $syslog
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    PostgreSQL RDBMS server
### END INIT INFO

# Setting environment variables for the postmaster here does not work; please
# set them in /etc/postgresql/<version>/<cluster>/environment instead.

[ -r /usr/share/postgresql-common/init.d-functions ] || exit 0

. /usr/share/postgresql-common/init.d-functions

# ORIGINAL version management disabled for Travis CI specific needs, see below
# versions can be specified explicitly
#if [ -n "$2" ]; then
#    versions="$2 $3 $4 $5 $6 $7 $8 $9"
#else
#    get_versions
#fi

# there should be only one running instance, and we must act in consequence...
running_version=$(pg_lsclusters -h | grep online | awk '{print $1}')

if [ -n "$2" ]; then
    versions="$2"
elif [ -n "$1" ] && [ $1 = 'stop' ]; then
    # be 100% sure to stop all instances (robustness hack)
    get_versions
elif [ -n "$running_version"  ]; then
    versions="$running_version"
else
    versions="<%= node['postgresql']['default_version'] %>"
fi

if [ -n "$1" ] && [ $1 != 'stop' ] && [ $1 != 'status' ]; then
    if [ -n "$running_version" ] && [ "$versions" != "$running_version" ]; then
        echo "Refused to $1 PostgreSQL $versions, because PostgreSQL $running_version is currently running! You should first stop $running_version instance..."
        exit 13
    fi
    if [ ! -d "/etc/postgresql/$versions" ]; then
        echo "PostgreSQL $versions is not installed!"
        exit 31
    fi
fi

<% if node['postgresql']['data_on_ramfs'] %>
# Copy initial databases to RAMFS
for data_dir in /var/lib/postgresql/*; do
    v=$(basename $data_dir)
    if [ -d $(dirname <%= node['postgresql']['data_dir'] %>) -a ! -d <%= node['postgresql']['data_dir'] %>/$v ]; then
        mkdir -p <%= node['postgresql']['data_dir'] %>/$v
        cp -rp $data_dir <%= node['postgresql']['data_dir'] %>/
    fi
done
<% end %>

case "$1" in
    start|stop|restart|reload)
        if [ -z "`pg_lsclusters -h`" ]; then
            log_warning_msg 'No PostgreSQL clusters exist; see "man pg_createcluster"'
            exit 0
        fi
        for v in $versions; do
            $1 $v || EXIT=$?
        done
        exit ${EXIT:-0}
        ;;
    status)
        LS=`pg_lsclusters -h`
        # no clusters -> unknown status
        [ -n "$LS" ] || exit 4
        echo "$LS" | awk 'BEGIN {rc=3} {if (match($4, "online")) rc=0; printf ("%s/%s (port %s): %s\n", $1, $2, $3, $4)}; END {exit rc}'
        ;;
    force-reload)
        for v in $versions; do
            reload $v
        done
        ;;
    *)
        echo "Usage: $0 {start|stop|restart|reload|force-reload|status} [version ..]"
{'fraction_non_alphanumeric': 0.15946173254835996, 'fraction_numerical': 0.015475189234650967, 'mean_word_length': 2.638922888616891, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6201655', 'n_tokens_mistral': 2040, 'n_tokens_neox': 1949, 'n_words': 606}