monero-project / monero

Monero: the secure, private, untraceable cryptocurrency
https://getmonero.org
Other
9k stars 3.12k forks source link

Support USR1 signal for log rotation #4413

Open ghost opened 6 years ago

ghost commented 6 years ago

When monerod and monero-wallet-rpc receives SIGUSR1 signal, they quit just like when they get SIGINT.

Most applications re-open their log files when they get SIGUSR1, and it makes log rotation easier.

I think it will be nice if monerod and the rest support them too.

moneromooo-monero commented 6 years ago

SIGUSR1 is usually a "re-read config" call.

ghost commented 6 years ago

No. SIGHUP typically reloads config (and re-opens log for some apps). For example, systemd sends /bin/kill -HUP $MAINPID when ExecReload is not defined.

SIGUSR1 is used by some programs (e.g. fluentd, auditd, squid, tomcat, dovecot, openvpn and many other...) to reopen logs.

moneromooo-monero commented 6 years ago

lol, I did confuse things indeed :D Sorry.

trasherdk commented 6 years ago

Regarding log rotation. Is it possible to do a copy-truncate instead of close-open? This will allow tail -f logfile.log | dosomething.sh to function across rotations.

moneromooo-monero commented 6 years ago

Seems useful to add.

moneromooo-monero commented 6 years ago

+hacktoberfest

trasherdk commented 5 years ago

Did the log file copy-truncate get implemented ?

And what about graceful shutdown ?

I'm currently using kill -HUP $(cat ${PID}) or kill -HUP $(pidof monerod) which is not exactly graceful.

moneromooo-monero commented 5 years ago

No, and yes, respectively.

trasherdk commented 5 years ago

I must have missed the commit/patch. Or is it in monero-v0.14.0.x ?

moneromooo-monero commented 5 years ago

A patch for... a graceful shutdown ? What kind of ungraceful shutdown are you having ?

trasherdk commented 5 years ago

When running monerod interactively, I'd do a save followed by exit to shut down. The log show the different stages of shutting down.

When running detached, I have to signal the daemon to shut down, and doing a kill -HUP $(cat ${PID}) it's like a crash. And the log just ends.

I'm running up to 3 monerod, bound to different ip addresses, on a local test server, plus 2 on remote servers.

moneromooo-monero commented 5 years ago

I'm confused. SIGHUP for log rotation is not implemented yet. And yet you are saying you're sending SIGHUP. Is it a simple case of "don't do that then" ? :) Am I missing something ?

moneromooo-monero commented 5 years ago

If it's that you don't know how to quit, you can use "monerod exit". Signal 15 should also work.

trasherdk commented 5 years ago

SIGHUP is used by many programs, as a "soft" way to tell it to end. Just like SIGQUIT, SIGKILL and SIGTERM. I've never used SIGHUP for logrotation.

When doing a $ ./monero-v0.13.0.4/monerod exit I get:

2019-02-22 17:31:51,465 INFO  [default] Page size: 4096
Error: Couldn't connect to daemon: 127.0.0.1:18081

And that's expected, as this instance is on 192.168.1.71:18081

trasherdk commented 5 years ago

Ok. SIGTERM is the graceful shutdown signal. $ kill -s TERM $(cat ${PID})

And come to think of it. $ curl -X POST http://192.168.1.71:18081/stop_daemon -H 'Content-Type: application/json' is just as good.

Thanks for your patience :)

moneromooo-monero commented 5 years ago

You'll have to add --p2p-bind-ip too for "monerod exit" to work. And --testnet/--stagenet if applicable I think.