LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-28-2009, 03:14 PM   #1
Joint PK
LQ Newbie
 
Registered: Dec 2009
Posts: 5

Rep: Reputation: 0
Flush server.log


Hello LQ

I have an program running, (edited.x86 = game server) and the output is logged into a server.log with 2> in the command line.

I want to backup the server.log every day This isn't a problem but, i want to make the server.log empty without restarting the server. I tried several codes

Code:
cat server.log > backup.log
echo -n > server.log
these commands do make a backup.log with the output and it does empty the server.log BUT the log doesn't save any new outputs. it just stops, but the size of the file increases constantly.

How can i fix this? or can i fix this?

greets,
Joint PK
 
Old 12-28-2009, 03:27 PM   #2
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
Depending on the particulars of the server you're using and the method it's using for logging you may be able to kill -HUP the process to get it reopen its file handles. Although if it wasn't originally designed for unix/linux it's likely that will disconnect players.
 
Old 12-28-2009, 03:56 PM   #3
Joint PK
LQ Newbie
 
Registered: Dec 2009
Posts: 5

Original Poster
Rep: Reputation: 0
So if im right, your saying that i have to kill the proces, wich means that the server will go offline and restart the server?
 
Old 12-28-2009, 04:35 PM   #4
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
Depending on how the process handles particular signals a HUP may kill and restart it or it may just close and reopen file handles or any variety of other things. Either research it for the individual application or try it while connected and see what happens and if new file handles get opened correctly a after log rotation.
 
Old 12-28-2009, 04:40 PM   #5
GooseYArd
Member
 
Registered: Jul 2009
Location: Reston, VA
Distribution: Slackware, Ubuntu, RHEL
Posts: 183

Rep: Reputation: 46
Quote:
Originally Posted by Joint PK View Post
So if im right, your saying that i have to kill the proces, wich means that the server will go offline and restart the server?
try this:

mv server.log server.log.1

tail -f server.log.1

the server should still be writing to server.log.1

killall -HUP edited.x86


now look and see if a new server.log got created. If it did, you're golden. You just mv/kill -HUP any time you want to rotate your log.

If it didn't you'll have to try something else.

Most long lived processes interpret sighup as a request to close and reopen the logfile handle, and reread the configuration, if there is one. The idea is that you can have the process perform some housekeeping, without, say, killing connections that are open to it.
 
Old 12-28-2009, 05:08 PM   #6
Joint PK
LQ Newbie
 
Registered: Dec 2009
Posts: 5

Original Poster
Rep: Reputation: 0
I have several servers running with the same name, the only difference is the port. Wouldn't this kill my server which makes it offline?
 
Old 12-28-2009, 10:41 PM   #7
GooseYArd
Member
 
Registered: Jul 2009
Location: Reston, VA
Distribution: Slackware, Ubuntu, RHEL
Posts: 183

Rep: Reputation: 46
nope. Kill doesn't kill processes, it sends signals to processes. Some signals normally cause a process to die. In fact, the _default_ signal that kill sends (if you don't give it one) is SIGTERM (15), which almost always stops the process.

http://en.wikipedia.org/wiki/Signal_...ist_of_signals

You can send other useful signals to processes using kill also. Signals like USR1 and USR2 are reserved so that you can add a custom signal handler to respond to them. Occasionally people will use USR1 as the log rotation signal, and you'd say 'kill -USR1 12345'.

HUP or "hangup" is leftover from the days of serial comms, and wound up getting co-opted for log rotation (among other things)
 
Old 12-29-2009, 10:46 AM   #8
Joint PK
LQ Newbie
 
Registered: Dec 2009
Posts: 5

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by GooseYArd View Post
try this:

mv server.log server.log.1

tail -f server.log.1
Till there works! but when i do

Quote:
the server should still be writing to server.log.1

killall -HUP edited.x86
The server stopts, shows offline. Is there any alternative?

like

Code:
tail -f server.log.1 > server.log
 
Old 12-29-2009, 11:22 AM   #9
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
Not particularly, it's just a poorly written daemon. You'll have to stop and restart it after you rotate the logs. Perhaps schedule it for Sunday at 4am or something similar.
 
Old 12-29-2009, 05:06 PM   #10
GooseYArd
Member
 
Registered: Jul 2009
Location: Reston, VA
Distribution: Slackware, Ubuntu, RHEL
Posts: 183

Rep: Reputation: 46
I would also try sending it a sigusr1 and sigusr2, just in case they happened to use that as the log reopen signal.

The only other alternative I can think of is to copy and truncate, I can't remember if you mentioned trying that.

Youd say:

cp server.log server.log.new
cat /dev/null > server.log

that way, the server continues writing to the same inode, but the file there gets truncated prior to the next write.
 
Old 12-30-2009, 12:00 PM   #11
Joint PK
LQ Newbie
 
Registered: Dec 2009
Posts: 5

Original Poster
Rep: Reputation: 0
Code:
cp server.log /home/backup/$file/log/$DATE.log
cat /dev/null > server.log
the file still has his old size, but doesn't have anything in it
 
  


Reply

Tags
centos, file, flush, gameserver, linux, log, server



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
In Apache server, How to change log file location and log format for access log fil? since1993 Linux - Server 1 08-19-2009 04:14 PM
the significance and name of the 5th column of /var/log/auth.log (ubuntu server)? CoffeeKing!!! Linux - Security 4 02-05-2009 07:32 AM
Can Samhain log my entries in /var/log/secure and /var/log/mesage to a central server abefroman Linux - Software 2 04-13-2008 04:13 PM
how to flush unused semaphores, after killing server Santoshkb Linux - Server 1 01-23-2008 09:57 AM
flush my server logs? mikz Linux - Security 1 03-14-2005 05:34 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration