Daemoninsing a rake task
Asked Answered
A

4

5

I have a rake task which runs mailman under the rails environment.

I'd like to ensure that rake task is always running via a daemon.

My rake task is rake incoming_mail

How would I go about daemonising that?

Aught answered 4/3, 2012 at 14:34 Comment(2)
Are you using linux or osx? What kind of features do you want this daemon to have?Wagshul
daemon stop and daemon startAught
W
3

If you are on linux you could consider using start-stop-daemon.

start-stop-daemon -S --pidfile /var/run/incoming_mail.pid -u rails_user -d /path/to/your/rails/app -b -a "rake incoming_mail"

To later gracefully kill the process you can use most of the arguments but replace -S with -K.

As always you can find more information on start-stop-daemon by reading the man pages.

Wagshul answered 4/3, 2012 at 17:21 Comment(0)
G
4

In linux in order to run a process in background, you can add & to the end of command. So

rake incoming_mail &

should probably do the jobs for you.

Geomancer answered 4/3, 2012 at 15:16 Comment(2)
how can I make sure the rake task is running once the rails app has been started.Aught
This solution just runs it in the background, which is fine, until you want to make sure the thing is up, and working.Acquainted
W
3

If you are on linux you could consider using start-stop-daemon.

start-stop-daemon -S --pidfile /var/run/incoming_mail.pid -u rails_user -d /path/to/your/rails/app -b -a "rake incoming_mail"

To later gracefully kill the process you can use most of the arguments but replace -S with -K.

As always you can find more information on start-stop-daemon by reading the man pages.

Wagshul answered 4/3, 2012 at 17:21 Comment(0)
N
0

If you use Ruby 1.9+, you could use Process.daemon. There's also a solution for Ruby < 1.9: http://www.jstorimer.com/blogs/workingwithcode/7766093-daemon-processes-in-ruby

Nucleoplasm answered 22/5, 2013 at 13:19 Comment(0)
D
0

If it's a docker image then surely it must be linux so,

rake incoming_mail &

should do the job by login into the pod and running rake task

Apart from this, put

Rails.logger.info in your code so the logs will be pushed to application log file OR

GCloud Stackdriver or any logging framework.

Desalinate answered 8/3, 2019 at 6:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.