From 13c04a6f477f49e3d33f6b71cf26e076a46d685f Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Mon, 2 Apr 2012 06:23:51 +0000 Subject: 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 --- sca-cpp/trunk/.gitignore | 1 + sca-cpp/trunk/components/cache/memcached-start | 4 +- sca-cpp/trunk/components/log/Makefile.am | 7 ++- sca-cpp/trunk/components/log/scribe-status.cpp | 66 ++++++++++++++++++++++++++ sca-cpp/trunk/components/log/scribe.hpp | 39 ++++++++++++++- sca-cpp/trunk/components/sqldb/pgsql-conf | 2 +- sca-cpp/trunk/components/sqldb/pgsql-start | 2 +- 7 files changed, 114 insertions(+), 7 deletions(-) create mode 100644 sca-cpp/trunk/components/log/scribe-status.cpp diff --git a/sca-cpp/trunk/.gitignore b/sca-cpp/trunk/.gitignore index 1a45e7cdbd..b43b8a7d7a 100644 --- a/sca-cpp/trunk/.gitignore +++ b/sca-cpp/trunk/.gitignore @@ -132,6 +132,7 @@ curl-get curl-connect rss-test scribe-cat +scribe-status js-test js-shell file-test diff --git a/sca-cpp/trunk/components/cache/memcached-start b/sca-cpp/trunk/components/cache/memcached-start index 947b583ec0..692a066010 100755 --- a/sca-cpp/trunk/components/cache/memcached-start +++ b/sca-cpp/trunk/components/cache/memcached-start @@ -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 diff --git a/sca-cpp/trunk/components/log/Makefile.am b/sca-cpp/trunk/components/log/Makefile.am index 92be162101..5d685babec 100644 --- a/sca-cpp/trunk/components/log/Makefile.am +++ b/sca-cpp/trunk/components/log/Makefile.am @@ -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 diff --git a/sca-cpp/trunk/components/log/scribe-status.cpp b/sca-cpp/trunk/components/log/scribe-status.cpp new file mode 100644 index 0000000000..0e5f03f501 --- /dev/null +++ b/sca-cpp/trunk/components/log/scribe-status.cpp @@ -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(host, port)); + + // Get its status + const failable 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])); +} + diff --git a/sca-cpp/trunk/components/log/scribe.hpp b/sca-cpp/trunk/components/log/scribe.hpp index a7fecf9865..7fa420f945 100644 --- a/sca-cpp/trunk/components/log/scribe.hpp +++ b/sca-cpp/trunk/components/log/scribe.hpp @@ -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 transport; friend const failable log(const value& val, const value& category, const Scribe& sc); + friend const failable status(const Scribe& sc); /** * Initialize the Scribe connection. @@ -147,6 +148,40 @@ const failable log(const value& val, const value& category, const Scribe& return true; } +/** + * Return Scribe status. + */ +const failable 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("Unknown status"); + } catch (const std::exception& e) { + return mkfailure(e.what()); + } +} + } } diff --git a/sca-cpp/trunk/components/sqldb/pgsql-conf b/sca-cpp/trunk/components/sqldb/pgsql-conf index 2cfe47880b..21222a1183 100755 --- a/sca-cpp/trunk/components/sqldb/pgsql-conf +++ b/sca-cpp/trunk/components/sqldb/pgsql-conf @@ -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'` diff --git a/sca-cpp/trunk/components/sqldb/pgsql-start b/sca-cpp/trunk/components/sqldb/pgsql-start index 4a7e1ebe23..2955bec991 100755 --- a/sca-cpp/trunk/components/sqldb/pgsql-start +++ b/sca-cpp/trunk/components/sqldb/pgsql-start @@ -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'` -- cgit v1.2.3