Bitcoin Forum
March 28, 2024, 02:40:16 PM *
News: Latest Bitcoin Core release: 26.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Don't forget to rotate your logs...  (Read 13125 times)
Gavin Andresen (OP)
Legendary
*
qt
Offline Offline

Activity: 1652
Merit: 2164


Chief Scientist


View Profile WWW
July 12, 2010, 04:39:47 PM
Last edit: November 18, 2010, 12:13:11 AM by gavinandresen
 #1

Reminder to anybody running a bitcoind server:   be sure the debug.log isn't filling up your server's disk.  With the slashdotting, now might be a good time to setup a debug.log housekeeping system.

I'm doing this on my Debian server:

My crontab:
Code:
# Rotate bitcoin logs
0 8 * * * /usr/sbin/logrotate --state /home/gavin/.bitcoin/logrotate.state /home/gavin/bc_logrotate.conf
My bc_logrotate.conf file:
Code:
#
# Rotate the bitcoin debug.log file
#
# This should be added to crontab to be run every day:
#  /usr/sbin/logrotate /path/to/bc_logrotate.conf
#
compress
copytruncate

/home/gavin/.bitcoin/debug.log {
rotate 5
}

How often do you get the chance to work on a potentially world-changing project?
1711636816
Hero Member
*
Offline Offline

Posts: 1711636816

View Profile Personal Message (Offline)

Ignore
1711636816
Reply with quote  #2

1711636816
Report to moderator
Make sure you back up your wallet regularly! Unlike a bank account, nobody can help you if you lose access to your BTC.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
lachesis
Full Member
***
Offline Offline

Activity: 210
Merit: 104


View Profile
July 12, 2010, 10:15:33 PM
 #2

Great idea, Gavin. Thanks for the code; I'll copy that exactly (except for the gavin part Smiley)

Bitcoin Calculator | Scallion | GPG Key | WoT Rating | 1QGacAtYA7E8V3BAiM7sgvLg7PZHk5WnYc
Gavin Andresen (OP)
Legendary
*
qt
Offline Offline

Activity: 1652
Merit: 2164


Chief Scientist


View Profile WWW
November 18, 2010, 12:18:11 AM
 #3

I just committed a change to svn to the way debug.log is written that means you need to change your logrotate configuration.

Why the change:  before, bitcoin was opening and closing debug.log on every print.  That caused it to be unusable on Macs running FileVault (and slower than it aught to be on various other systems).

After subversion rev 183, bitcoin will keep debug.log open and just append to it.

If you're rotating logs using the unix logrotate command, just add 'copytruncate' to its configuration file and the right thing will happen.  I changed the example in my post above.

How often do you get the chance to work on a potentially world-changing project?
theymos
Administrator
Legendary
*
Offline Offline

Activity: 5152
Merit: 12580


View Profile
November 18, 2010, 12:27:37 AM
 #4

Bitcoin already limits the size of debug.log.

1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
throughput
Full Member
***
Offline Offline

Activity: 158
Merit: 100


View Profile
November 18, 2010, 08:07:09 AM
 #5

I just committed a change to svn to the way debug.log is written that means you need to change your logrotate configuration.

Why the change:  before, bitcoin was opening and closing debug.log on every print.  That caused it to be unusable on Macs running FileVault (and slower than it aught to be on various other systems).

After subversion rev 183, bitcoin will keep debug.log open and just append to it.

If you're rotating logs using the unix logrotate command, just add 'copytruncate' to its configuration file and the right thing will happen.  I changed the example in my post above.

Oh, my dear, why not you just haven't invented some new rpc command, like "reopenlogs" ?
dmp1ce
Member
**
Offline Offline

Activity: 69
Merit: 10


View Profile WWW
April 11, 2011, 01:26:24 PM
 #6

Bitcoin already limits the size of debug.log.

What does Bitcoin limit the log size to?  I keep losing most of my log data and I'm wondering if Bitcoin keeps deleting it and starting over.

BTCmon - Support great bitcoin apps
dmp1ce
Member
**
Offline Offline

Activity: 69
Merit: 10


View Profile WWW
April 11, 2011, 02:05:08 PM
 #7

Nevermind, I think I found it.  It looks like 10 MB is when Bitcoin decides to reset the debug.log.

Code:
void ShrinkDebugFile()
{
    // Scroll debug.log if it's getting too big
    string strFile = GetDataDir() + "/debug.log";
    FILE* file = fopen(strFile.c_str(), "r");
    if (file && GetFilesize(file) > 10 * 1000000)
    { 
        // Restart the file with some of the end
        char pch[200000];
        fseek(file, -sizeof(pch), SEEK_END);
        int nBytes = fread(pch, 1, sizeof(pch), file);
        fclose(file);
        if (file = fopen(strFile.c_str(), "w"))
        { 
            fwrite(pch, 1, nBytes, file);
            fclose(file);
        }
    }
}

BTCmon - Support great bitcoin apps
theymos
Administrator
Legendary
*
Offline Offline

Activity: 5152
Merit: 12580


View Profile
April 12, 2011, 11:57:19 AM
 #8

It only does it on startup, so the file might actually get bigger than 10MB.

1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
M4v3R
Hero Member
*****
Offline Offline

Activity: 607
Merit: 500


View Profile
April 12, 2011, 10:35:36 PM
 #9

Yes, mine was around 100 MB after a longer while. Thanks for the logrotate tip, now it's back to normal Smiley.
error
Hero Member
*****
Offline Offline

Activity: 588
Merit: 500



View Profile
July 27, 2011, 08:47:40 PM
 #10

Or perhaps reopen the log on SIGHUP, like most other services?

3KzNGwzRZ6SimWuFAgh4TnXzHpruHMZmV8
phillipsjk
Legendary
*
Offline Offline

Activity: 1008
Merit: 1001

Let the chips fall where they may.


View Profile WWW
February 23, 2014, 07:08:04 PM
 #11

FreeBSD uses a log rotator called newsyslog.

The following line in /etc/newsyslog.conf appears to do the right thing:
Code:
/home/bitcoin/debug.log bitcoin:bitcoin 644  5     100  *  JR /home/bitcoin/sighup.sh

The fields are separated by white-space. They are: 'logfile_name', 'owner:group', 'mode', 'count' (number of archives to keep), 'size' (in kb), 'when' (chose anytime), 'flags' (J->Bzip2, R-> Treat next field as as shell command to run), 'path_to_pid_cmd_file' (filename containing daemon's PID, must start with /), 'signal_number' (optional, omitted in example).

I first tried appending "killall -HUP bitcoind" directly, but the arguments were interpreted as an invalid signal number. With the size limited to 100 kB, the logs get rotated every hour (because they they grow faster than that).

sighup.sh is just a simple shell-script:
Code:
#!/bin/sh
#Sends bitcoind a Sighup.
killall -HUP bitcoind


I was not able to find any 'copytruncate', setting, but it appears to do the right thing.

James' OpenPGP public key fingerprint: EB14 9E5B F80C 1F2D 3EBE  0A2F B3DE 81FF 7B9D 5160
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!