mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-25 21:19:24 +01:00
Merge pull request #2 from PurpleI2P/openssl
graceful shutdown by SIGINT
This commit is contained in:
commit
e7e24804b8
2 changed files with 41 additions and 21 deletions
7
Daemon.h
7
Daemon.h
|
@ -65,12 +65,17 @@ namespace i2p
|
||||||
|
|
||||||
bool start();
|
bool start();
|
||||||
bool stop();
|
bool stop();
|
||||||
; void run ();
|
void run ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::string pidfile;
|
std::string pidfile;
|
||||||
int pidFH;
|
int pidFH;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
int gracefullShutdownInterval; // in seconds
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "FS.h"
|
#include "FS.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
|
#include "RouterContext.h"
|
||||||
|
|
||||||
void handle_signal(int sig)
|
void handle_signal(int sig)
|
||||||
{
|
{
|
||||||
|
@ -21,9 +22,13 @@ void handle_signal(int sig)
|
||||||
LogPrint(eLogInfo, "Daemon: Got SIGHUP, reopening log...");
|
LogPrint(eLogInfo, "Daemon: Got SIGHUP, reopening log...");
|
||||||
i2p::log::Logger().Reopen ();
|
i2p::log::Logger().Reopen ();
|
||||||
break;
|
break;
|
||||||
|
case SIGINT:
|
||||||
|
i2p::context.SetAcceptsTunnels (false);
|
||||||
|
Daemon.gracefullShutdownInterval = 10*60; // 10 minutes
|
||||||
|
LogPrint(eLogInfo, "Graceful shutdown after ", Daemon.gracefullShutdownInterval, " seconds");
|
||||||
|
break;
|
||||||
case SIGABRT:
|
case SIGABRT:
|
||||||
case SIGTERM:
|
case SIGTERM:
|
||||||
case SIGINT:
|
|
||||||
Daemon.running = 0; // Exit loop
|
Daemon.running = 0; // Exit loop
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -96,6 +101,7 @@ namespace i2p
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
gracefullShutdownInterval = 0; // not specified
|
||||||
|
|
||||||
// Signal handler
|
// Signal handler
|
||||||
struct sigaction sa;
|
struct sigaction sa;
|
||||||
|
@ -122,6 +128,15 @@ namespace i2p
|
||||||
while (running)
|
while (running)
|
||||||
{
|
{
|
||||||
std::this_thread::sleep_for (std::chrono::seconds(1));
|
std::this_thread::sleep_for (std::chrono::seconds(1));
|
||||||
|
if (gracefullShutdownInterval)
|
||||||
|
{
|
||||||
|
gracefullShutdownInterval--; // - 1 second
|
||||||
|
if (gracefullShutdownInterval <= 0)
|
||||||
|
{
|
||||||
|
LogPrint(eLogInfo, "Graceful shutdown");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue