Skip to content

Commit

Permalink
Moved reopening of log to SIGUSR1 (16)
Browse files Browse the repository at this point in the history
Added --pidfile option to init.d script
  • Loading branch information
r4sas committed Jan 29, 2017
1 parent 2d46cb0 commit f722b3e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
32 changes: 18 additions & 14 deletions DaemonLinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,23 @@ void handle_signal(int sig)
switch (sig)
{
case SIGHUP:
LogPrint(eLogInfo, "Daemon: Got SIGHUP, reopening logs and tunnel configuration...");
i2p::log::Logger().Reopen ();
LogPrint(eLogInfo, "Daemon: Got SIGHUP, reopening tunnel configuration...");
i2p::client::context.ReloadConfig();
break;
case SIGUSR1:
LogPrint(eLogInfo, "Daemon: Got SIGUSR1, reopening logs...");
i2p::log::Logger().Reopen ();
break;
case SIGINT:
if (i2p::context.AcceptsTunnels () && !Daemon.gracefulShutdownInterval)
{
{
i2p::context.SetAcceptsTunnels (false);
Daemon.gracefulShutdownInterval = 10*60; // 10 minutes
LogPrint(eLogInfo, "Graceful shutdown after ", Daemon.gracefulShutdownInterval, " seconds");
}
}
else
Daemon.running = 0;
break;
Daemon.running = 0;
break;
case SIGABRT:
case SIGTERM:
Daemon.running = 0; // Exit loop
Expand Down Expand Up @@ -77,7 +80,7 @@ namespace i2p
}

// point std{in,out,err} descriptors to /dev/null
freopen("/dev/null", "r", stdin);
freopen("/dev/null", "r", stdin);
freopen("/dev/null", "w", stdout);
freopen("/dev/null", "w", stderr);
}
Expand All @@ -101,8 +104,8 @@ namespace i2p
}
uint32_t cfsize; i2p::config::GetOption("limits.coresize", cfsize);
if (cfsize) // core file size set
{
cfsize *= 1024;
{
cfsize *= 1024;
getrlimit(RLIMIT_CORE, &limit);
if (cfsize <= limit.rlim_max) {
limit.rlim_cur = cfsize;
Expand All @@ -116,7 +119,7 @@ namespace i2p
} else {
LogPrint(eLogError, "Daemon: limits.coresize exceeds system limit: ", limit.rlim_max);
}
}
}

// Pidfile
// this code is c-styled and a bit ugly, but we need fd for locking pidfile
Expand Down Expand Up @@ -153,6 +156,7 @@ namespace i2p
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART;
sigaction(SIGHUP, &sa, 0);
sigaction(SIGUSR1, &sa, 0);
sigaction(SIGABRT, &sa, 0);
sigaction(SIGTERM, &sa, 0);
sigaction(SIGINT, &sa, 0);
Expand All @@ -164,7 +168,7 @@ namespace i2p
{
i2p::fs::Remove(pidfile);

return Daemon_Singleton::stop();
return Daemon_Singleton::stop();
}

void DaemonLinux::run ()
Expand All @@ -175,12 +179,12 @@ namespace i2p
if (gracefulShutdownInterval)
{
gracefulShutdownInterval--; // - 1 second
if (gracefulShutdownInterval <= 0)
{
if (gracefulShutdownInterval <= 0)
{
LogPrint(eLogInfo, "Graceful shutdown");
return;
}
}
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion debian/i2pd.init
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ do_start()
|| return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --chuid "$USER" -- \
--service --daemon --log=file --logfile=$LOGFILE --conf=$I2PCONF --tunconf=$TUNCONF \
$DAEMON_OPTS > /dev/null 2>&1 \
--pidfile=$PIDFILE $DAEMON_OPTS > /dev/null 2>&1 \
|| return 2
return $?
}
Expand Down

1 comment on commit f722b3e

@r4sas
Copy link
Member Author

@r4sas r4sas commented on f722b3e Jan 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.