LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 05-03-2016, 10:23 AM   #1
jon_the_eye
LQ Newbie
 
Registered: Jun 2010
Posts: 7

Rep: Reputation: 0
setting up a command line as a service with logging


Hi

I am setting up the very useful freegeoip tool (http://freegeoip.net)

I have put it in /usr/sbin and can happily start it with:

/usr/sbin/freegeoip &

- When its running it logs its output to the console.

I want to do two things:
1. Write the log file to /var/log/freegeoip.log (or something similar) and get the log to rotate (like maillog and vsftpd do). I have tried ">" and "|" into logger, but it didn't work.

2. Get it to start when the machine starts and be able to control it with "service" command line.
 
Old 05-03-2016, 12:59 PM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,294
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
Which distro are you using and which version? Those are two areas where they can vary a bit.

A generic, quick-and-dirty option for getting it to start automatically that might work for your system could be to launch it from rc.local

Code:
/usr/sbin/freegeoip > /var/log/freegeoip.log 2>&1 &
The log file has to be owned or otherwise writable by the account running the program. Group permissions work, too.

Then, if your system has it, put in a line in /etc/logrotate.conf and restart the daemon. logrotate.conf has its own manual page with details, but you can also copy one of the existing settings and adapt it. Be sure to set the right user, group and permissions in the configuration.
 
Old 05-04-2016, 02:33 AM   #3
jon_the_eye
LQ Newbie
 
Registered: Jun 2010
Posts: 7

Original Poster
Rep: Reputation: 0
Thanks. "turbo" That command line works great - it's now logging to the log folder.

Sorry, forgot to mention my distro - I am running Centos 6.4/64bit

I've added it to rc.local and it is started on reboot, when it reboots it overwrites the log file, but this is fine.

Ideally, I'd like to get the log files to rotate and create a script in /etc/init.d to control it as a normal service, but as I have a working solution, I will leave it for now.

Regards
 
Old 05-04-2016, 02:50 AM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,294
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
Quote:
Originally Posted by jon_the_eye View Post
I've added it to rc.local and it is started on reboot, when it reboots it overwrites the log file, but this is fine.
Then appending should save the logs between reboots.

Code:
/usr/sbin/freegeoip >> /var/log/freegeoip.log 2>&1 &
About the log rotation, you can put a file in /etc/logrotate.d/ named freegeoip containing something like the following:

Code:
/var/log/freegeoip.log {
        missingok
        notifempty
        rotate 12345
        weekly
        create 644 foo bar
}
Where "create" has the permissions, user, and group that you want for the log file. weekly can be substituted with daily or hourly or yearly or whatever. See the manual page for logrotate(8) for the details and make sure you have what you need rather than copying the above verbatim.
 
  


Reply

Tags
services, shell scripting



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
how to allow the nfs service in the firewall from the command line ztdep SUSE / openSUSE 1 03-27-2015 10:55 AM
Logging into router from command line michael.wegemer Linux - General 14 03-24-2010 09:21 AM
Logging all mysql command line operations Linville79 Linux - Server 8 06-19-2008 01:51 PM
doinkd - starts on command line but not as service car182 Linux - Server 2 10-21-2006 09:37 AM
logging in from command line and doing su cause weird messages sunpascal Linux - Newbie 2 02-10-2006 09:05 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 03:12 AM.

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