1 #include <boost/program_options.hpp>
2 #include <boost/shared_ptr.hpp>
8 #include "protobufrpc.h"
10 using namespace bicker;
11 using namespace boost;
12 using namespace kvstore;
15 namespace po = boost::program_options;
17 int interrupted_count = 0;
18 ProtoBufRpcServer rpc_server;
21 interrupted(int /*signal*/)
23 if (interrupted_count < 1)
25 rpc_server.shutdown();
40 shared_ptr<thread> server_thread;
42 /* Initialize Exception Handling */
43 struct sigaction action;
45 action.sa_handler = &interrupted;
46 action.sa_flags = SA_SIGINFO;
47 sigemptyset(&action.sa_mask);
49 if (sigaction(SIGINT, &action, NULL) == -1)
60 po::options_description options("Options");
63 ("help,h", "display help message")
65 po::value< vector<string> >(),
66 "bdb home directories")
68 po::value<uint16_t>(&opt_port)->default_value(9090),
70 ("foreground,f", "don't fork to the background")
71 ("sleep,s", po::value<uint16_t>(&opt_sleep)->default_value(0), "sleep then exit")
75 po::store(po::parse_command_line(argc, argv, options), vm);
80 cerr << options << endl;
87 if (vm.count("bdb-home") > 0)
89 paths = vm["bdb-home"].as< vector<string> >();
93 paths.push_back("./");
97 shared_ptr<Service> service(new KeyValueRpcService(new BDBBackend(paths)));
99 rpc_server.registerService(opt_port, service);
104 &ProtoBufRpcServer::run,
107 if (!vm.count("foreground"))
110 if (daemon(0,0) != 0)
112 perror("daemonizing");
119 server_thread->join();
123 time_t t0 = time(NULL);
129 sleep(opt_sleep - (t1 - t0));
130 } while (t1 - t0 < opt_sleep);
132 rpc_server.shutdown();