Detach Memcached and Pgsql from terminal when logging with a logger like Scribe. Add a Scribe status command.

git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1308246 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
jsdelfino 2012-04-02 06:23:51 +00:00
commit 13c04a6f47
7 changed files with 114 additions and 7 deletions

View file

@ -132,6 +132,7 @@ curl-get
curl-connect
rss-test
scribe-cat
scribe-status
js-test
js-shell
file-test

View file

@ -44,8 +44,8 @@ mkdir -p $root/memcached
echo $log > $root/memcached/logger
if [ "$ip" = "" ]; then
($memcached_prefix/bin/memcached -d -m 4 -p $port $v 2>&1 | sh $root/memcached/logger)&
nohup /bin/sh -c "($memcached_prefix/bin/memcached -d -m 4 -p $port $v 2>&1 | sh $root/memcached/logger)" 1>/dev/null 2>/dev/null &
else
($memcached_prefix/bin/memcached -d -l $ip -m 4 -p $port $v 2>&1 | sh $root/memcached/logger)&
nohup /bin/sh -c "($memcached_prefix/bin/memcached -d -l $ip -m 4 -p $port $v 2>&1 | sh $root/memcached/logger)" 1>/dev/null 2>/dev/null &
fi

View file

@ -57,13 +57,18 @@ liblogger_la_LDFLAGS = -L${THRIFT_LIB} -R${THRIFT_LIB} -lthrift -L${FB303_LIB} -
liblogger${libsuffix}:
ln -s .libs/liblogger${libsuffix}
comp_PROGRAMS = scribe-cat
comp_PROGRAMS = scribe-cat scribe-status
nodist_scribe_cat_SOURCES = gen-cpp/fb303_constants.cpp gen-cpp/fb303_types.cpp gen-cpp/scribe_constants.cpp gen-cpp/scribe.cpp gen-cpp/scribe_types.cpp gen-cpp/FacebookService.cpp gen-cpp/scribe.h
scribe_cat_CXXFLAGS = -Wno-unused-parameter -Wno-conversion -Wno-return-type
scribe_cat_SOURCES = scribe-cat.cpp
scribe_cat_LDFLAGS = -L${THRIFT_LIB} -R${THRIFT_LIB} -lthrift -L${FB303_LIB} -R${FB303_LIB} -lfb303 -L${SCRIBE_LIB} -R${SCRIBE_LIB} -lscribe
nodist_scribe_status_SOURCES = gen-cpp/fb303_constants.cpp gen-cpp/fb303_types.cpp gen-cpp/scribe_constants.cpp gen-cpp/scribe.cpp gen-cpp/scribe_types.cpp gen-cpp/FacebookService.cpp gen-cpp/scribe.h
scribe_status_CXXFLAGS = -Wno-unused-parameter -Wno-conversion -Wno-return-type
scribe_status_SOURCES = scribe-status.cpp
scribe_status_LDFLAGS = -L${THRIFT_LIB} -R${THRIFT_LIB} -lthrift -L${FB303_LIB} -R${FB303_LIB} -lfb303 -L${SCRIBE_LIB} -R${SCRIBE_LIB} -lscribe
client_test_SOURCES = client-test.cpp
client_test_LDFLAGS = -lxml2 -lcurl -lmozjs

View file

@ -0,0 +1,66 @@
/*
* 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.
*/
/* $Rev$ $Date$ */
/**
* A utility that logs stdin into a scribe log.
*/
#include "string.hpp"
#include "function.hpp"
#include "list.hpp"
#include "value.hpp"
#include "monad.hpp"
#undef debug
#define debug(...)
#include "scribe.hpp"
namespace tuscany {
namespace scribestatus {
const int status(const string& host, const int port) {
// Connect to Scribe
scribe::Scribe& sc = *(new (gc_new<scribe::Scribe>()) scribe::Scribe(host, port));
// Get its status
const failable<string> fs = scribe::status(sc);
// Interpret and display results
if (!hasContent(fs)) {
cerr << reason(fs) << endl;
return 2;
}
const string s = content(fs);
cout << s << endl;
if (s == "ALIVE")
return 0;
if (s == "STARTING" || s == "STOPPING" || s == "WARNING")
return 1;
return 2;
}
}
}
int main(const int argc, const char** argv) {
return tuscany::scribestatus::status(argc < 2? "localhost" : argv[1], argc < 3? 1463 : atoi(argv[2]));
}

View file

@ -37,7 +37,7 @@
#undef OK
// Ignore integer conversion issues in Thrift and Scribe headers
#ifdef WANT_MAINTAINER_MODE
#ifdef WANT_MAINTAINER_WARNINGS
#pragma GCC diagnostic ignored "-Wconversion"
#endif
@ -47,7 +47,7 @@
#include "gen-cpp/scribe.h"
#ifdef WANT_MAINTAINER_MODE
#ifdef WANT_MAINTAINER_WARNINGS
#pragma GCC diagnostic warning "-Wconversion"
#endif
@ -99,6 +99,7 @@ private:
boost::shared_ptr<apache::thrift::transport::TTransport> transport;
friend const failable<bool> log(const value& val, const value& category, const Scribe& sc);
friend const failable<string> status(const Scribe& sc);
/**
* Initialize the Scribe connection.
@ -147,6 +148,40 @@ const failable<bool> log(const value& val, const value& category, const Scribe&
return true;
}
/**
* Return Scribe status.
*/
const failable<string> status(const Scribe& sc) {
debug("scribe::status");
try {
::facebook::fb303::fb_status s = sc.client->getStatus();
switch(s) {
case ::facebook::fb303::DEAD:
debug("DEAD", "scribe::status::result");
return string("DEAD");
case ::facebook::fb303::STARTING:
debug("STARTING", "scribe::status::result");
return string("STARTING");
case ::facebook::fb303::ALIVE:
debug("ALIVE", "scribe::status::result");
return string("ALIVE");
case ::facebook::fb303::STOPPING:
debug("STOPPING", "scribe::status::result");
return string("STOPPING");
case ::facebook::fb303::STOPPED:
debug("STOPPED", "scribe::status::result");
return string("STOPPED");
case ::facebook::fb303::WARNING:
debug("WARNING", "scribe::status::result");
return string("WARNING");
}
return mkfailure<string>("Unknown status");
} catch (const std::exception& e) {
return mkfailure<string>(e.what());
}
}
}
}

View file

@ -98,7 +98,7 @@ host replication all samenet trust
EOF
# Create the db
($pgsql_prefix/bin/pg_ctl start -W -D $root/sqldb/data 2>&1 | sh $root/sqldb/logger)&
nohup /bin/sh -c "($pgsql_prefix/bin/pg_ctl start -W -D $root/sqldb/data 2>&1 | sh $root/sqldb/logger)" 1>/dev/null 2>/dev/null &
sti=0
while [ $sti -ne 30 ]; do
st=`$pgsql_prefix/bin/pg_ctl status -D $root/sqldb/data | grep 'server is running'`

View file

@ -32,7 +32,7 @@ fi
mkdir -p $root/sqldb
echo $pgsql_log >$root/sqldb/logger
($pgsql_prefix/bin/pg_ctl start -W -D $root/sqldb/data 2>&1 | sh $root/sqldb/logger)&
nohup /bin/sh -c "($pgsql_prefix/bin/pg_ctl start -W -D $root/sqldb/data 2>&1 | sh $root/sqldb/logger)" 1>/dev/null 2>/dev/null &
sti=0
while [ $sti -ne 30 ]; do
st=`$pgsql_prefix/bin/pg_ctl status -D $root/sqldb/data | grep 'server is running'`