Browse Source

graceful shutdown by SIGINT

pull/458/merge
orignal 9 years ago
parent
commit
db88183a23
  1. 7
      Daemon.h
  2. 15
      DaemonLinux.cpp

7
Daemon.h

@ -65,12 +65,17 @@ namespace i2p @@ -65,12 +65,17 @@ namespace i2p
bool start();
bool stop();
; void run ();
void run ();
private:
std::string pidfile;
int pidFH;
public:
int gracefullShutdownInterval; // in seconds
};
#endif
}

15
DaemonLinux.cpp

@ -21,9 +21,12 @@ void handle_signal(int sig) @@ -21,9 +21,12 @@ void handle_signal(int sig)
LogPrint(eLogInfo, "Daemon: Got SIGHUP, reopening log...");
i2p::log::Logger().Reopen ();
break;
case SIGINT:
Daemon.gracefullShutdownInterval = 10*60; // 10 minutes
LogPrint(eLogInfo, "Graceful shutdown after ", Daemon.gracefullShutdownInterval, " seconds");
break;
case SIGABRT:
case SIGTERM:
case SIGINT:
Daemon.running = 0; // Exit loop
break;
}
@ -96,6 +99,7 @@ namespace i2p @@ -96,6 +99,7 @@ namespace i2p
return false;
}
}
gracefullShutdownInterval = 0; // not specified
// Signal handler
struct sigaction sa;
@ -122,6 +126,15 @@ namespace i2p @@ -122,6 +126,15 @@ namespace i2p
while (running)
{
std::this_thread::sleep_for (std::chrono::seconds(1));
if (gracefullShutdownInterval)
{
gracefullShutdownInterval--; // - 1 second
if (gracefullShutdownInterval <= 0)
{
LogPrint(eLogInfo, "Graceful shutdown");
return;
}
}
}
}
}

Loading…
Cancel
Save