thuehlinger / daemons

Ruby daemons gem official repository
MIT License
648 stars 71 forks source link

How to set pid file location? #20

Closed Paxa closed 9 years ago

Paxa commented 10 years ago

When I run it, it only create file in current folder. How to change it to /var/run/app.pid or any other folder?

sodabrew commented 10 years ago

According to https://github.com/thuehlinger/daemons/blob/master/lib/daemons/pidfile.rb

Daemons is configurable to store the Pid-Files relative to three different locations:

  1. in a directory relative to the directory where the script (the one that is supposed to run as a daemon) resides (:script option for :dir_mode)
  2. in a directory given by :dir (:normal option for :dir_mode)
  3. in the preconfigured directory /var/run (:system option for :dir_mode)
Paxa commented 10 years ago

Nice. Can you give an example how to make in /opt/pids/my-app.pid ?

sodabrew commented 10 years ago

Daemons.daemonize(:dir => '/opt/pids')

Paxa commented 10 years ago

But how to make pidfile name not same with application name?

thuehlinger commented 10 years ago

Daemons.daemonize(:app_name => 'custom_app_name', :dir => '/opt/pids')

sodabrew commented 9 years ago

@Paxa or @thuehlinger I think this question is answered and can be closed.

Paxa commented 9 years ago

I still can't make different name for process and pid file.

for example process name my_daemon, and pid_file daemon_process.pid

As I see in source code it use same name for pid and proces name

Aetherus commented 9 years ago

You can set the sub process name in the sub process itself, like this:

Daemons.run_proc('pid_file_name') do
  # Set the process name
  $0 = 'my_fancy_process'

  # Do whatever as a daemon
end