mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 02:44:15 +00:00
graceful shutdown by SIGINT
This commit is contained in:
parent
25dbf62274
commit
db88183a23
31
Daemon.h
31
Daemon.h
@ -50,26 +50,31 @@ namespace i2p
|
|||||||
|
|
||||||
bool init(int argc, char* argv[]);
|
bool init(int argc, char* argv[]);
|
||||||
bool start();
|
bool start();
|
||||||
bool stop();
|
bool stop();
|
||||||
void run ();
|
void run ();
|
||||||
};
|
};
|
||||||
#else
|
#else
|
||||||
class DaemonLinux : public Daemon_Singleton
|
class DaemonLinux : public Daemon_Singleton
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static DaemonLinux& Instance()
|
static DaemonLinux& Instance()
|
||||||
{
|
{
|
||||||
static DaemonLinux instance;
|
static DaemonLinux instance;
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool start();
|
bool start();
|
||||||
bool stop();
|
bool stop();
|
||||||
; void run ();
|
void run ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string pidfile;
|
|
||||||
int pidFH;
|
std::string pidfile;
|
||||||
|
int pidFH;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
int gracefullShutdownInterval; // in seconds
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -17,14 +17,17 @@ void handle_signal(int sig)
|
|||||||
{
|
{
|
||||||
switch (sig)
|
switch (sig)
|
||||||
{
|
{
|
||||||
case SIGHUP:
|
case SIGHUP:
|
||||||
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 SIGABRT:
|
case SIGINT:
|
||||||
case SIGTERM:
|
Daemon.gracefullShutdownInterval = 10*60; // 10 minutes
|
||||||
case SIGINT:
|
LogPrint(eLogInfo, "Graceful shutdown after ", Daemon.gracefullShutdownInterval, " seconds");
|
||||||
Daemon.running = 0; // Exit loop
|
break;
|
||||||
|
case SIGABRT:
|
||||||
|
case SIGTERM:
|
||||||
|
Daemon.running = 0; // Exit loop
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -96,6 +99,7 @@ namespace i2p
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
gracefullShutdownInterval = 0; // not specified
|
||||||
|
|
||||||
// Signal handler
|
// Signal handler
|
||||||
struct sigaction sa;
|
struct sigaction sa;
|
||||||
@ -122,6 +126,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…
x
Reference in New Issue
Block a user