mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-08 22:13:48 +01:00
Log to file, reload config and daemon mode
This commit is contained in:
parent
82bd8cc69f
commit
8f1e300b13
2 changed files with 84 additions and 9 deletions
17
README.md
17
README.md
|
@ -26,14 +26,21 @@ $ ./i2p --host=YOUR_PUBLIC_IP
|
||||||
|
|
||||||
The client should now reseed by itself.
|
The client should now reseed by itself.
|
||||||
|
|
||||||
Other options:
|
|
||||||
* --port= - The port to listen on
|
|
||||||
* --httpport= - The http port to listen on
|
|
||||||
|
|
||||||
|
|
||||||
To visit an I2P page, you need to find the b32 address of your destination.
|
To visit an I2P page, you need to find the b32 address of your destination.
|
||||||
After that, go to the webconsole and add it behind the url. (Remove http:// and b32.i2p from the address)
|
After that, go to the webconsole and add it behind the url. (Remove http:// and b32.i2p from the address)
|
||||||
|
|
||||||
This should resulting in for example:
|
This should resulting in for example:
|
||||||
http://localhost:7070/4oes3rlgrpbkmzv4lqcfili23h3cvpwslqcfjlk6vvguxyggspwa
|
http://localhost:7070/4oes3rlgrpbkmzv4lqcfili23h3cvpwslqcfjlk6vvguxyggspwa
|
||||||
|
|
||||||
|
|
||||||
|
Options
|
||||||
|
-------
|
||||||
|
|
||||||
|
* --host= - The external IP
|
||||||
|
* --port= - The port to listen on
|
||||||
|
* --httpport= - The http port to listen on
|
||||||
|
* --log= - Enable or disable logging to file. 1 for yes, 0 for no.
|
||||||
|
* --daemon= - Eanble or disable daemon mode. 1 for yes, 0 for no.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
70
i2p.cpp
70
i2p.cpp
|
@ -2,6 +2,9 @@
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <cryptopp/integer.h>
|
#include <cryptopp/integer.h>
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "base64.h"
|
#include "base64.h"
|
||||||
#include "Transports.h"
|
#include "Transports.h"
|
||||||
|
@ -13,6 +16,21 @@
|
||||||
#include "HTTPServer.h"
|
#include "HTTPServer.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
void handle_sighup(int n)
|
||||||
|
{
|
||||||
|
if (i2p::util::config::GetArg("daemon", 0) == 1)
|
||||||
|
{
|
||||||
|
static bool first=true;
|
||||||
|
if (first)
|
||||||
|
{
|
||||||
|
first=false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LogPrint("Reloading config.");
|
||||||
|
i2p::util::filesystem::ReadConfigFile(i2p::util::config::mapArgs, i2p::util::config::mapMultiArgs);
|
||||||
|
}
|
||||||
|
|
||||||
int main( int argc, char* argv[] )
|
int main( int argc, char* argv[] )
|
||||||
{
|
{
|
||||||
i2p::util::config::OptionParser(argc,argv);
|
i2p::util::config::OptionParser(argc,argv);
|
||||||
|
@ -23,10 +41,51 @@ int main( int argc, char* argv[] )
|
||||||
setlocale(LC_ALL, "Russian");
|
setlocale(LC_ALL, "Russian");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
LogPrint("\n\n\n\ni2pd starting\n");
|
LogPrint("\n\n\n\ni2pd starting\n");
|
||||||
LogPrint("data directory: ", i2p::util::filesystem::GetDataDir().string());
|
LogPrint("data directory: ", i2p::util::filesystem::GetDataDir().string());
|
||||||
i2p::util::filesystem::ReadConfigFile(i2p::util::config::mapArgs, i2p::util::config::mapMultiArgs);
|
i2p::util::filesystem::ReadConfigFile(i2p::util::config::mapArgs, i2p::util::config::mapMultiArgs);
|
||||||
|
|
||||||
|
struct sigaction sa;
|
||||||
|
sa.sa_handler = handle_sighup;
|
||||||
|
sigemptyset(&sa.sa_mask);
|
||||||
|
sa.sa_flags = SA_RESTART;
|
||||||
|
if (sigaction(SIGHUP,&sa,0) == -1)
|
||||||
|
{
|
||||||
|
LogPrint("Failed to install SIGHUP handler.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i2p::util::config::GetArg("-daemon", 0) == 1)
|
||||||
|
{
|
||||||
|
pid_t pid;
|
||||||
|
pid = fork();
|
||||||
|
if (pid > 0)
|
||||||
|
{
|
||||||
|
g_Log.Stop();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (pid < 0)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
umask(0);
|
||||||
|
int sid = setsid();
|
||||||
|
if (sid < 0)
|
||||||
|
{
|
||||||
|
LogPrint("Error, could not create process group.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i2p::util::config::GetArg("-log", 0) == 1)
|
||||||
|
{
|
||||||
|
std::string logfile = i2p::util::filesystem::GetDataDir().string();
|
||||||
|
logfile.append("/debug.log");
|
||||||
|
LogPrint("Logging to file enabled.");
|
||||||
|
freopen(logfile.c_str(),"a",stdout);
|
||||||
|
}
|
||||||
|
|
||||||
//TODO: This is an ugly workaround. fix it.
|
//TODO: This is an ugly workaround. fix it.
|
||||||
//TODO: Autodetect public IP.
|
//TODO: Autodetect public IP.
|
||||||
i2p::context.OverrideNTCPAddress(i2p::util::config::GetCharArg("-host", "127.0.0.1"),
|
i2p::context.OverrideNTCPAddress(i2p::util::config::GetCharArg("-host", "127.0.0.1"),
|
||||||
|
@ -40,10 +99,19 @@ int main( int argc, char* argv[] )
|
||||||
i2p::transports.Start ();
|
i2p::transports.Start ();
|
||||||
i2p::tunnel::tunnels.Start ();
|
i2p::tunnel::tunnels.Start ();
|
||||||
|
|
||||||
std::this_thread::sleep_for (std::chrono::seconds(10000));
|
int running = 1;
|
||||||
|
while (running)
|
||||||
|
{
|
||||||
|
std::this_thread::sleep_for (std::chrono::seconds(1000));
|
||||||
|
}
|
||||||
|
|
||||||
i2p::tunnel::tunnels.Stop ();
|
i2p::tunnel::tunnels.Stop ();
|
||||||
i2p::transports.Stop ();
|
i2p::transports.Stop ();
|
||||||
i2p::data::netdb.Stop ();
|
i2p::data::netdb.Stop ();
|
||||||
httpServer.Stop ();
|
httpServer.Stop ();
|
||||||
|
if (i2p::util::config::GetArg("-log", 0) == 1)
|
||||||
|
{
|
||||||
|
fclose (stdout);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue