0

I am using daemon to wrap my script and has specified logs location into that : Script looks like this :

#!/usr/local/bin/ruby
require 'rubygems'
require 'daemons'

Daemons.run_proc(
   'script_test', # name of daemon
   :log_output => true,
   :output_logfilename => "script-test.log",
   :logfilename => "script-test.log"
 ) do
   exec 'ruby /opt/script-test/script-test.rb'
end

Problem is my logs are storing in same directory where my script is present. I have to add my logs to different directory such as /var/log/script-test and later have to rotate those logs weekly. Provide me with a solution so that i can store the logs of script in /var/log directory.

2 Answers2

0

Make sure you are using an absolute path instead of a relative path

For example:

:output_logfilename => "/var/log/script-test.log",
:logfilename => "/var/log/script-test.log"

In order to logrotate your logs, (assuming Linux) add the following to your logrotate config to rotate on a weekly basis:

/var/log/script-test.log {
  weekly
  missingok
  compress
  notifempty
  copytruncate
}
Martin Konecny
  • 57,827
  • 19
  • 139
  • 159
0

It worked for me with this configuration as :

Daemons.run_proc(
   'script-test', # name of daemon
   :log_output => true,
   :dir_mode => :normal,
   :dir => "/var/log",
   :output_logfilename => "script-test.log",
   :logfilename => "script-test.log"
 ) do
   exec 'ruby /opt/script-test/script-test.rb'

end