aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xetc/apachectl97
-rwxr-xr-xetc/brep31
-rw-r--r--etc/config25
-rw-r--r--etc/httpd.conf30
-rwxr-xr-xetc/pgctl143
5 files changed, 280 insertions, 46 deletions
diff --git a/etc/apachectl b/etc/apachectl
index 1039c50..8f58896 100755
--- a/etc/apachectl
+++ b/etc/apachectl
@@ -22,33 +22,27 @@
# When multiple arguments are given, only the error from the _last_
# one is reported. Run "apachectl help" for usage info
-ARGV="$@"
-#
-# |||||||||||||||||||| START CONFIGURATION SECTION ||||||||||||||||||||
-# -------------------- --------------------
-
-export PORT=7180
-export SERVER_NAME="cppget.org:$PORT"
-export LOG_LEVEL=trace1
-export ADMIN_EMAIL=admin@cppget.org
+. `dirname $0`/config
-export DB_HOST=localhost
-export DB_PORT=7136
-
-# |||||||||||||||||||| END CONFIGURATION SECTION |||||||||||||||||||||||
-
-PROJECT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/..
+ARGV="$@"
-export MODULE_DIR="$PROJECT_DIR"
-export WWW_DIR="$PROJECT_DIR/www"
-export CONFIG_DIR="$PROJECT_DIR/etc"
-export WORKSPACE_DIR="$PROJECT_DIR/var"
+export AP_LOG_LEVEL
+export AP_ADMIN_EMAIL
+export AP_PORT
+export AP_SERVER_NAME
+export AP_DB_HOST
+export AP_DB_PORT
+export AP_MODULE_DIR
+export AP_WWW_DIR
+export AP_CONFIG_DIR
+export AP_WORKSPACE_DIR
-mkdir -p "$WORKSPACE_DIR"
+mkdir -p "$AP_WORKSPACE_DIR"
+mkdir -p "$AP_LOG_DIR"
# the path to your httpd binary, including options if necessary
-HTTPD="/usr/sbin/httpd -d $WORKSPACE_DIR -f $CONFIG_DIR/httpd.conf"
+HTTPD="/usr/sbin/httpd -d $AP_LOG_DIR -f $AP_CONFIG_DIR/httpd.conf"
# a command that outputs a formatted text version of the HTML at the
# url given on the command line. Designed for lynx, however other
@@ -57,7 +51,7 @@ LYNX="lynx -dump"
# the URL to your server's mod_status status page. If you do not
# have one, then status and fullstatus will not work.
-STATUSURL="http://localhost:$PORT/server-status"
+STATUSURL="http://localhost:$AP_PORT/server-status"
# Set this variable to a command that increases the maximum
# number of file descriptors allowed per child process. This is
@@ -74,32 +68,73 @@ fi
ERROR=0
if [ "x$ARGV" = "x" ] ; then
- ARGV="-h"
+ ARGV="-h"
fi
case $ARGV in
-start) $HTTPD -k $ARGV
- ERROR=$?
+ start)
+ $LYNX $STATUSURL 1>/dev/null 2>&1
+
+ if test $? -eq 0; then
+ echo "Apache server already running"
+ ERROR=$?
+ else
+ echo "Apache server starting ..."
+ $HTTPD -k $ARGV
+ ERROR=$?
+
+ if test $ERROR -eq 0; then
+ echo "server started"
+ else
+ echo "server starting failed"
+ fi
+ fi
;;
-stop|restart|graceful)
+
+stop)
+ $LYNX $STATUSURL 1>/dev/null 2>&1
+
+ if test $? -eq 0; then
+ echo "Apache server stopping ..."
+ $HTTPD -k $ARGV
+ ERROR=$?
+
+ if test $ERROR -eq 0; then
+ echo "server stopped"
+ else
+ echo "server stopping failed"
+ fi
+ else
+ echo "Apache server not running"
+ ERROR=$?
+ fi
+ ;;
+
+ restart|graceful)
$HTTPD -k $ARGV
ERROR=$?
;;
-startssl|sslstart|start-SSL)
+
+ startssl|sslstart|start-SSL)
$HTTPD -k start -DSSL
ERROR=$?
;;
-configtest)
+
+ configtest)
$HTTPD -t
ERROR=$?
;;
-status)
+
+ status)
+ echo "checking Apache server status ..."
$LYNX $STATUSURL | awk ' /process$/ { print; exit } { print } '
;;
-fullstatus)
+
+ fullstatus)
$LYNX $STATUSURL
;;
-*)
+
+ *)
$HTTPD $ARGV
ERROR=$?
esac
diff --git a/etc/brep b/etc/brep
new file mode 100755
index 0000000..3ec448b
--- /dev/null
+++ b/etc/brep
@@ -0,0 +1,31 @@
+#!/bin/sh
+# file : etc/brep
+# copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
+# license : MIT; see accompanying LICENSE file
+#
+# Designed to simplify controlling brep services.
+
+CMD="$1"
+SCRIPT_DIR=`dirname $0`
+
+case $CMD in
+ start|stop|status) ;;
+ *)
+ echo "Usage: brep (start|stop|status)"
+ exit 1
+ ;;
+esac
+
+case $CMD in
+ start)
+ $SCRIPT_DIR/pgctl start && $SCRIPT_DIR/apachectl start
+ ;;
+ stop)
+ $SCRIPT_DIR/apachectl stop
+ $SCRIPT_DIR/pgctl stop
+ ;;
+ status)
+ $SCRIPT_DIR/pgctl status
+ $SCRIPT_DIR/apachectl status
+ ;;
+esac
diff --git a/etc/config b/etc/config
new file mode 100644
index 0000000..a1e851c
--- /dev/null
+++ b/etc/config
@@ -0,0 +1,25 @@
+# Basic settings (used in this file only)
+SCRIPT_DIR=`dirname $0`
+CONFIG_DIR=`cd $SCRIPT_DIR; pwd`
+PROJECT_DIR="$CONFIG_DIR/.."
+WORKSPACE_DIR="$PROJECT_DIR/var"
+
+# PostgreSQL settings (used in pgctl)
+PG_PORT=8432
+PG_DATA_DIR="$WORKSPACE_DIR/lib/pgsql"
+PG_SOCKET_DIR="$WORKSPACE_DIR/run/pgsql"
+PG_LOG_DIR="$WORKSPACE_DIR/log/pgsql"
+PG_OUT_FILE="$WORKSPACE_DIR/run/pgsql/out"
+
+# Apache settings (used in apachectl)
+AP_PORT=8080
+AP_SERVER_NAME="cppget.org:$AP_PORT"
+AP_ADMIN_EMAIL=admin@cppget.org
+AP_LOG_LEVEL=trace1
+AP_DB_HOST="$PG_SOCKET_DIR"
+AP_DB_PORT=$PG_PORT
+AP_MODULE_DIR="$PROJECT_DIR"
+AP_WWW_DIR="$PROJECT_DIR/www"
+AP_CONFIG_DIR="$CONFIG_DIR"
+AP_LOG_DIR="$WORKSPACE_DIR/log/httpd"
+AP_WORKSPACE_DIR="$WORKSPACE_DIR/run/httpd"
diff --git a/etc/httpd.conf b/etc/httpd.conf
index b52b7d0..bf64517 100644
--- a/etc/httpd.conf
+++ b/etc/httpd.conf
@@ -1,18 +1,18 @@
-Listen ${PORT}
-ServerName "${SERVER_NAME}"
-ServerAdmin "${ADMIN_EMAIL}"
+Listen ${AP_PORT}
+ServerName "${AP_SERVER_NAME}"
+ServerAdmin "${AP_ADMIN_EMAIL}"
User apache
Group apache
-DocumentRoot "${WWW_DIR}/htdocs"
-CoreDumpDirectory "${WORKSPACE_DIR}"
-PidFile "${WORKSPACE_DIR}/httpd.pid"
+DocumentRoot "${AP_WWW_DIR}/htdocs"
+CoreDumpDirectory "${AP_WORKSPACE_DIR}"
+PidFile "${AP_WORKSPACE_DIR}/httpd.pid"
#ErrorLog error_log
ErrorLog "|/usr/sbin/rotatelogs error_log.%Y%m%d 86400"
ErrorLogFormat "[%t] [%l] [%m] %M"
-LogLevel ${LOG_LEVEL}
+LogLevel ${AP_LOG_LEVEL}
Timeout 60
KeepAlive On
@@ -40,20 +40,20 @@ LoadModule authz_host_module /usr/lib64/httpd/modules/mod_authz_host.so
LoadModule expires_module /usr/lib64/httpd/modules/mod_expires.so
LoadModule dir_module /usr/lib64/httpd/modules/mod_dir.so
-LoadModule search_srv ${MODULE_DIR}/libbrep.so
+LoadModule search_srv ${AP_MODULE_DIR}/libbrep.so
<IfModule search_srv>
- search-db-host ${DB_HOST}
- search-db-port ${DB_PORT}
- search-conf "${CONFIG_DIR}/search.conf"
+ search-db-host ${AP_DB_HOST}
+ search-db-port ${AP_DB_PORT}
+ search-conf "${AP_CONFIG_DIR}/search.conf"
</IfModule>
-LoadModule view_srv ${MODULE_DIR}/libbrep.so
+LoadModule view_srv ${AP_MODULE_DIR}/libbrep.so
<IfModule view_srv>
- view-db-host ${DB_HOST}
- view-db-port ${DB_PORT}
- view-conf "${CONFIG_DIR}/view.conf"
+ view-db-host ${AP_DB_HOST}
+ view-db-port ${AP_DB_PORT}
+ view-conf "${AP_CONFIG_DIR}/view.conf"
</IfModule>
<LocationMatch ^/search$>
diff --git a/etc/pgctl b/etc/pgctl
new file mode 100755
index 0000000..26ad888
--- /dev/null
+++ b/etc/pgctl
@@ -0,0 +1,143 @@
+#!/bin/sh
+# file : etc/pgctl
+# copyright : Copyright (c) 2014-2015 Code Synthesis Ltd
+# license : MIT; see accompanying LICENSE file
+#
+# Designed to simplify controlling brep PostgreSQL server instance.
+
+. `dirname $0`/config
+
+cmd="$1"
+
+# Print usage description and exit.
+#
+case $cmd in
+ init|start|stop|status|connect) ;;
+ *)
+ echo "Usage: pgctl (init|start|stop|status|connect)"
+ exit 1
+ ;;
+esac
+
+ERROR=0
+
+# Initilization includes creating PostgreSQL DB cluster, creating and
+# populating brep DB.
+#
+if test "$cmd" = "init"; then
+ if test -d "$PG_DATA_DIR"; then
+ echo "PostgreSQL DB cluster directory $PG_DATA_DIR already exist"
+ else
+ echo "creating PostgreSQL DB cluster ..."
+ pg_ctl initdb -D "$PG_DATA_DIR"
+ ERROR=$?
+
+ if test $ERROR -eq 0; then
+ echo "cluster created"
+ else
+ echo "cluster creating failed"
+ exit $ERROR;
+ fi
+ fi
+fi
+
+case $cmd in
+ start|init)
+ # Start DB server if not running yet.
+ #
+ pg_ctl status -D "$PG_DATA_DIR" 1>/dev/null 2>&1
+
+ if test $? -eq 0; then
+ echo "PostgreSQL server already running"
+ else
+ if test ! -d "$PG_DATA_DIR"; then
+ echo "PostgreSQL DB cluster not exist; run '$0 init' first"
+ exit 1
+ fi
+
+ echo "PostgreSQL server starting ..."
+
+ mkdir -p `dirname $PG_OUT_FILE`
+ mkdir -p "$PG_LOG_DIR"
+ mkdir -p "$PG_SOCKET_DIR"
+
+ pg_ctl start -D "$PG_DATA_DIR" -w -o \
+ "-c port=$PG_PORT -c unix_socket_directories=$PG_SOCKET_DIR \
+ -c logging_collector=on -c log_directory=$PG_LOG_DIR" \
+ 1>"$PG_OUT_FILE" 2>&1
+
+ ERROR=$?
+
+ if test $ERROR -eq 0; then
+ echo "server started"
+ else
+ cat "$PG_OUT_FILE" 1>&2
+ echo "server starting failed"
+ exit $ERROR
+ fi
+ fi
+ ;;
+
+ status)
+ echo "checking PostgreSQL server status ..."
+ pg_ctl status -D "$PG_DATA_DIR"
+ ;;
+
+ stop)
+ pg_ctl status -D "$PG_DATA_DIR" 1>/dev/null 2>&1
+
+ if test $? -eq 0; then
+ echo "PostgreSQL server stopping ..."
+ pg_ctl stop -D "$PG_DATA_DIR"
+ ERROR=$?
+
+ if test $ERROR -eq 0; then
+ : # pg_ctl prints "server stopped" on success
+ else
+ echo "server stopping failed"
+ exit $ERROR
+ fi
+ else
+ echo "PostgreSQL server not running"
+ fi
+ ;;
+
+ connect)
+ echo "connecting to PostgreSQL server ..."
+ psql --host=$PG_SOCKET_DIR --port=$PG_PORT brep
+ ;;
+esac
+
+if test "$cmd" = "init"; then
+ # Create brep DB if not exist.
+ #
+ psql --host=$PG_SOCKET_DIR --port=$PG_PORT -c "" brep \
+ 1>>"$PG_OUT_FILE" 2>&1
+
+ ERROR=$?
+
+ if test $ERROR -eq 0; then
+ echo "brep DB already exist"
+ else
+ if test $ERROR -eq 2; then
+ echo "creating brep DB ..."
+ createdb --host=$PG_SOCKET_DIR --port=$PG_PORT brep
+ ERROR=$?
+
+ if test $ERROR -eq 0; then
+ echo "brep DB created"
+ else
+ echo "brep DB creating failed"
+ exit $ERROR;
+ fi
+ else
+ echo "brep DB existence checking failed"
+ exit $ERROR;
+ fi
+ fi
+
+ # Populate brep DB if required.
+ # psql --host=$PG_SOCKET_DIR --port=$PG_PORT -c "select count(1) ..." brep \
+ # 1>>"$PG_OUT_FILE" 2>&1
+ # ...
+fi