Add external configuration of Memcached and PostgreSQL logging, to allow the logs to be piped to Scribe or the HTTPD log rotation program.
git-svn-id: https://svn.apache.org/repos/asf/tuscany/sca-cpp/trunk@1225904 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/components/cache/Makefile.am b/components/cache/Makefile.am
index 159a941..d14bd3a 100644
--- a/components/cache/Makefile.am
+++ b/components/cache/Makefile.am
@@ -18,7 +18,7 @@
incl_HEADERS = *.hpp
incldir = $(prefix)/include/components/cache
-dist_comp_SCRIPTS = memcached-start memcached-stop
+dist_comp_SCRIPTS = memcached-log-conf memcached-start memcached-stop
compdir=$(prefix)/components/cache
comp_DATA = memcached.prefix
diff --git a/components/cache/memcached-log-conf b/components/cache/memcached-log-conf
new file mode 100755
index 0000000..d8a4896
--- /dev/null
+++ b/components/cache/memcached-log-conf
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Configure memcached logging
+here=`echo "import os; print os.path.realpath('$0')" | python`; here=`dirname $here`
+mkdir -p $1
+root=`echo "import os; print os.path.realpath('$1')" | python`
+
+mkdir -p $root/memcached
+if [ "$2" = "" ]; then
+ cat >$root/memcached/log.conf << EOF
+cat >>$root/logs/memcached
+EOF
+
+else
+ cat >$root/memcached/log.conf << EOF
+$2
+EOF
+
+fi
+
diff --git a/components/cache/memcached-start b/components/cache/memcached-start
index 0946da2..a49ad29 100755
--- a/components/cache/memcached-start
+++ b/components/cache/memcached-start
@@ -19,8 +19,9 @@
# Start memcached
here=`echo "import os; print os.path.realpath('$0')" | python`; here=`dirname $here`
+root=`echo "import os; print os.path.realpath('$1')" | python`
-addr=$1
+addr=$2
if [ "$addr" = "" ]; then
ip=""
port="11211"
@@ -30,9 +31,19 @@
fi
memcached_prefix=`cat $here/memcached.prefix`
-if [ "$ip" = "" ]; then
- $memcached_prefix/bin/memcached -d -m 4 -p $port
+
+if [ -f "$root/memcached/log.conf" ]; then
+ log=`cat $root/memcached/log.conf`
+ v="-vv"
else
- $memcached_prefix/bin/memcached -d -l $ip -m 4 -p $port
+ mkdir -p $root/logs
+ log="cat >>$root/logs/memcached"
+ v=""
+fi
+
+if [ "$ip" = "" ]; then
+ ($memcached_prefix/bin/memcached -d -m 4 -p $port $v 2>&1 | $log)&
+else
+ ($memcached_prefix/bin/memcached -d -l $ip -m 4 -p $port $v 2>&1 | $log)&
fi
diff --git a/components/sqldb/Makefile.am b/components/sqldb/Makefile.am
index faa10ec..0443de0 100644
--- a/components/sqldb/Makefile.am
+++ b/components/sqldb/Makefile.am
@@ -22,7 +22,7 @@
incl_HEADERS = *.hpp
incldir = $(prefix)/include/components/sqldb
-dist_comp_SCRIPTS = pgsql-conf pgsql-start pgsql-stop pgsql pgsql-standby-conf pgsql-backup
+dist_comp_SCRIPTS = pgsql-conf pgsql-log-conf pgsql-start pgsql-stop pgsql pgsql-standby-conf pgsql-backup
compdir=$(prefix)/components/sqldb
comp_DATA = pgsql.prefix
diff --git a/components/sqldb/pgsql b/components/sqldb/pgsql
index 23b78b9..8079fde 100755
--- a/components/sqldb/pgsql
+++ b/components/sqldb/pgsql
@@ -31,5 +31,9 @@
cmd="$3"
fi
-$pgsql_prefix/bin/psql -h $host -p $port -c "$cmd" db
+if [ "$cmd" = "" ]; then
+ $pgsql_prefix/bin/psql -h $host -p $port db
+else
+ $pgsql_prefix/bin/psql -h $host -p $port -c "$cmd" db
+fi
diff --git a/components/sqldb/pgsql-backup b/components/sqldb/pgsql-backup
index 0c2a128..3c0be60 100755
--- a/components/sqldb/pgsql-backup
+++ b/components/sqldb/pgsql-backup
@@ -30,12 +30,20 @@
fi
pgsql_prefix=`cat $here/pgsql.prefix`
-$pgsql_prefix/bin/psql -h $host -p $port -c "SELECT pg_start_backup('backup', true)" db 1>>$root/logs/postgresql 2>&1
+
+if [ -f "$root/sqldb/log.conf" ]; then
+ pgsql_log=`cat $root/sqldb/log.conf`
+else
+ mkdir -p $root/logs
+ pgsql_log="cat >>$root/logs/postgresql"
+fi
+
+$pgsql_prefix/bin/psql -h $host -p $port -c "SELECT pg_start_backup('backup', true)" db 2>&1 | $pgsql_log
echo "Content-type: application/x-compressed"
echo
tar -C $root/sqldb -cz data
-$pgsql_prefix/bin/psql -h $host -p $port -c "SELECT pg_stop_backup()" db 1>>$root/logs/postgresql 2>&1
+$pgsql_prefix/bin/psql -h $host -p $port -c "SELECT pg_stop_backup()" db 2>&1 | $pgsql_log
diff --git a/components/sqldb/pgsql-conf b/components/sqldb/pgsql-conf
index f0ea218..e3eb1c8 100755
--- a/components/sqldb/pgsql-conf
+++ b/components/sqldb/pgsql-conf
@@ -38,9 +38,16 @@
mkdir -p $root/sqldb/data
chmod 700 $root/sqldb/data
mkdir -p $root/sqldb/archive
-mkdir -p $root/logs
+
+if [ -f "$root/sqldb/log.conf" ]; then
+ pgsql_log=`cat $root/sqldb/log.conf`
+else
+ mkdir -p $root/logs
+ pgsql_log="cat >>$root/logs/postgresql"
+fi
+
if [ ! -f $root/sqldb/data/postgresql.conf ]; then
- $pgsql_prefix/bin/pg_ctl init -D $root/sqldb/data 1>>$root/logs/postgresql 2>&1
+ $pgsql_prefix/bin/pg_ctl init -D $root/sqldb/data 2>&1 | $pgsql_log
cp $root/sqldb/data/postgresql.conf $root/sqldb/data/postgresql-init.conf
cp $root/sqldb/data/pg_hba.conf $root/sqldb/data/pg_hba-init.conf
fi
@@ -51,6 +58,17 @@
# Generated by: pgsql-conf $*
+# Setup logging
+log_min_messages = INFO
+log_min_error_statement = INFO
+log_min_duration_statement = 0
+log_checkpoints = on
+log_connections = on
+log_disconnections = on
+log_duration = on
+log_lock_waits = on
+log_statement = all
+
# Listen
listen_addresses = '$ip'
port = $port
@@ -78,9 +96,19 @@
EOF
# Create the db
-$pgsql_prefix/bin/pg_ctl start -w -D $root/sqldb/data -l $root/logs/postgresql 1>>$root/logs/postgresql 2>&1
-$pgsql_prefix/bin/createdb -h localhost -p $port db 1>>$root/logs/postgresql 2>&1
-$pgsql_prefix/bin/pg_ctl stop -w -D $root/sqldb/data 1>>$root/logs/postgresql 2>&1
+($pgsql_prefix/bin/pg_ctl start -W -D $root/sqldb/data 2>&1 | $pgsql_log)&
+sti=0
+while [ $sti -ne 30 ]; do
+ st=`$pgsql_prefix/bin/pg_ctl status -D $root/sqldb/data | grep 'server is running'`
+ if [ "$st" != "" ]; then
+ break
+ fi
+ sleep 1
+ sti=$((sti+1))
+done
+
+$pgsql_prefix/bin/createdb -h localhost -p $port db 2>&1 | $pgsql_log
+$pgsql_prefix/bin/pg_ctl stop -w -D $root/sqldb/data 2>&1 | $pgsql_log
# Generate database backup script
mkdir -p $root/sqldb/scripts
diff --git a/components/sqldb/pgsql-log-conf b/components/sqldb/pgsql-log-conf
new file mode 100755
index 0000000..c68b4b7
--- /dev/null
+++ b/components/sqldb/pgsql-log-conf
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Configure postgresql logging
+here=`echo "import os; print os.path.realpath('$0')" | python`; here=`dirname $here`
+mkdir -p $1
+root=`echo "import os; print os.path.realpath('$1')" | python`
+
+mkdir -p $root/sqldb
+if [ "$2" = "" ]; then
+ cat >$root/sqldb/log.conf << EOF
+cat >>$root/logs/postgresql
+EOF
+
+else
+ cat >$root/sqldb/log.conf << EOF
+$2
+EOF
+
+fi
+
diff --git a/components/sqldb/pgsql-standby-conf b/components/sqldb/pgsql-standby-conf
index 5fcb712..291d950 100755
--- a/components/sqldb/pgsql-standby-conf
+++ b/components/sqldb/pgsql-standby-conf
@@ -47,14 +47,21 @@
fi
pgsql_prefix=`cat $here/pgsql.prefix`
+
+if [ -f "$root/sqldb/log.conf" ]; then
+ pgsql_log=`cat $root/sqldb/log.conf`
+else
+ mkdir -p $root/logs
+ pgsql_log="cat >>$root/logs/postgresql"
+fi
+
mkdir -p $root/sqldb/data
chmod 700 $root/sqldb/data
mkdir -p $root/sqldb/archive
-mkdir -p $root/logs
# Initialize from a backup of the master
if [ ! -f $root/sqldb/data/postgresql.conf ]; then
- (wget http://$mhost:$mhttpport/pgsql-backup -O - | tar -C $root/sqldb -xz) 1>>$root/logs/postgresql 2>&1
+ (wget http://$mhost:$mhttpport/pgsql-backup -O - | tar -C $root/sqldb -xz) 2>&1 | $pgsql_log
rm -rf $root/sqldb/data/postmaster.pid $root/sqldb/data/pg_xlog
mkdir -p $root/sqldb/data/pg_xlog/archive_status
chmod 700 $root/sqldb/data/pg_xlog/archive_status
diff --git a/components/sqldb/pgsql-start b/components/sqldb/pgsql-start
index ac35e80..9960c5d 100755
--- a/components/sqldb/pgsql-start
+++ b/components/sqldb/pgsql-start
@@ -22,8 +22,22 @@
root=`echo "import os; print os.path.realpath('$1')" | python`
pgsql_prefix=`cat $here/pgsql.prefix`
-mkdir -p $root/sqldb
-mkdir -p $root/logs
-$pgsql_prefix/bin/pg_ctl start -w -D $root/sqldb/data -l $root/logs/postgresql 1>>$root/logs/postgresql 2>&1
-sleep 1
+
+if [ -f "$root/sqldb/log.conf" ]; then
+ pgsql_log=`cat $root/sqldb/log.conf`
+else
+ mkdir -p $root/logs
+ pgsql_log="cat >>$root/logs/postgresql"
+fi
+
+($pgsql_prefix/bin/pg_ctl start -W -D $root/sqldb/data 2>&1 | $pgsql_log)&
+sti=0
+while [ $sti -ne 30 ]; do
+ st=`$pgsql_prefix/bin/pg_ctl status -D $root/sqldb/data | grep 'server is running'`
+ if [ "$st" != "" ]; then
+ break
+ fi
+ sleep 1
+ sti=$((sti+1))
+done
diff --git a/components/sqldb/pgsql-stop b/components/sqldb/pgsql-stop
index e226b35..9c5c9aa 100755
--- a/components/sqldb/pgsql-stop
+++ b/components/sqldb/pgsql-stop
@@ -22,6 +22,13 @@
root=`echo "import os; print os.path.realpath('$1')" | python`
pgsql_prefix=`cat $here/pgsql.prefix`
-mkdir -p $root/logs
-$pgsql_prefix/bin/pg_ctl stop -w -D $root/sqldb/data 1>>$root/logs/postgresql 2>&1
+
+if [ -f "$root/sqldb/log.conf" ]; then
+ pgsql_log=`cat $root/sqldb/log.conf`
+else
+ mkdir -p $root/logs
+ pgsql_log="cat >>$root/logs/postgresql"
+fi
+
+$pgsql_prefix/bin/pg_ctl stop -w -D $root/sqldb/data 2>&1 | $pgsql_log