Basic daemon support
This commit is contained in:
parent
494e8314f1
commit
37c965019b
4
Makefile
4
Makefile
|
@ -18,7 +18,7 @@
|
|||
#
|
||||
|
||||
objects = main.o udpTracker.o database.o driver_sqlite.o \
|
||||
tools.o httpserver.o webapp.o logging.o
|
||||
tools.o httpserver.o webapp.o logging.o tracker.o
|
||||
target = udpt
|
||||
|
||||
%.o: src/%.c
|
||||
|
@ -33,7 +33,7 @@ all: $(target)
|
|||
|
||||
$(target): $(objects)
|
||||
@echo Linking...
|
||||
$(CXX) -O3 -o $(target) $(objects) $(LDFLAGS) -lboost_program_options -lsqlite3 -lpthread
|
||||
$(CXX) -O3 -o $(target) $(objects) $(LDFLAGS) -lboost_program_options -lsqlite3 -lpthread -lboost_thread -lboost_system
|
||||
@echo Done.
|
||||
clean:
|
||||
@echo Cleaning Up...
|
||||
|
|
|
@ -15,7 +15,7 @@ We use [SQLite3](http://www.sqlite.org/) which is public-domain, and [Boost](htt
|
|||
We didn't really work on creating any installer, at the moment you can just run udpt from anywhere on your filesystem.
|
||||
Building udpt is pretty straightforward, just download the project or clone the repo:
|
||||
|
||||
UDPT requires the SQLite3 develpment package to be installed.
|
||||
UDPT requires the SQLite3, boost_program_options and boost_thread develpment packages to be installed.
|
||||
|
||||
<pre>
|
||||
$ git clone https://github.com/naim94a/udpt.git
|
||||
|
|
|
@ -33,17 +33,16 @@
|
|||
#include "tracker.hpp"
|
||||
|
||||
UDPT::Logger *logger = NULL;
|
||||
UDPT::Tracker *instance = NULL;
|
||||
|
||||
|
||||
static void _signal_handler(int sig)
|
||||
{
|
||||
switch (sig)
|
||||
{
|
||||
case SIGTERM:
|
||||
instance->stop();
|
||||
UDPT::Tracker::getInstance().stop();
|
||||
break;
|
||||
case SIGHUP:
|
||||
// TODO: Reload config.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -73,7 +72,6 @@ static void daemonize(const boost::program_options::variables_map& conf)
|
|||
int main(int argc, char *argv[])
|
||||
{
|
||||
Tracker& tracker = UDPT::Tracker::getInstance();
|
||||
instance = &tracker;
|
||||
|
||||
#ifdef WIN32
|
||||
WSADATA wsadata;
|
||||
|
@ -186,8 +184,6 @@ int main(int argc, char *argv[])
|
|||
tracker.start(var_map);
|
||||
tracker.wait();
|
||||
|
||||
std::cerr << "Bye." << std::endl;
|
||||
|
||||
#ifdef WIN32
|
||||
::WSACleanup();
|
||||
#endif
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace UDPT
|
|||
if (conf["apiserver.enable"].as<bool>())
|
||||
{
|
||||
m_apiSrv = std::shared_ptr<UDPT::Server::HTTPServer>(new UDPT::Server::HTTPServer(conf));
|
||||
m_webApp = std::shared_ptr<UDPT::Server::WebApp>(new UDPT::Server::WebApp(m_apiSrv, m_udpTracker->conn, conf));
|
||||
m_webApp = std::shared_ptr<UDPT::Server::WebApp>(new UDPT::Server::WebApp(m_apiSrv, m_udpTracker->m_conn.get(), conf));
|
||||
m_webApp->deploy();
|
||||
}
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ namespace UDPT
|
|||
|
||||
UDPTracker::~UDPTracker()
|
||||
{
|
||||
// left empty.
|
||||
stop();
|
||||
}
|
||||
|
||||
void UDPTracker::start()
|
||||
|
@ -141,17 +141,18 @@ namespace UDPT
|
|||
|
||||
for (std::vector<boost::thread>::iterator it = m_threads.begin(); it != m_threads.end(); ++it)
|
||||
{
|
||||
std::cout << "Interrupted thread " << it->get_id() << std::endl;
|
||||
it->interrupt();
|
||||
}
|
||||
|
||||
for (std::vector<boost::thread>::iterator it = m_threads.begin(); it != m_threads.end(); ++it)
|
||||
{
|
||||
std::cout << "waiting for " << it->get_id() << std::endl;
|
||||
it->join();
|
||||
wait();
|
||||
}
|
||||
|
||||
std::cout << "All threads terminated." << std::endl;
|
||||
void UDPTracker::wait()
|
||||
{
|
||||
for (std::vector<boost::thread>::iterator it = m_threads.begin(); it != m_threads.end(); ++it)
|
||||
{
|
||||
it->join();
|
||||
}
|
||||
}
|
||||
|
||||
int UDPTracker::sendError(UDPTracker* usi, SOCKADDR_IN* remote, uint32_t transactionID, const std::string &msg)
|
||||
|
|
|
@ -131,6 +131,11 @@ namespace UDPT
|
|||
*/
|
||||
void stop();
|
||||
|
||||
/**
|
||||
* Joins worker threads
|
||||
*/
|
||||
void wait();
|
||||
|
||||
/**
|
||||
* Destroys resources that were created by constructor
|
||||
* @param usi Instance to destroy.
|
||||
|
|
Loading…
Reference in a new issue