2

I have some ruby processes, and for development I've been using foreman to manage the processes, now in production I want to export the processes and run it in /etc/init.d directory.

Is there any tool that can help with that, by creating the scripts and the related PID to /var/run ? I tried to use foreman export feature to do so, but it didn't work to do that, since it can do something for inittab or upstart but not init.d.

Any help would be highly appreciated

Eki Eqbal
  • 5,779
  • 9
  • 47
  • 81
  • I prefer using [God](http://godrb.com) to run my ruby apps in production. – Sergio Tulentsev Nov 06 '12 at 13:52
  • I know, but it's not about managing ruby processes, I'm using Monit already but it's not the case, I'm just looking for a tool to help me create the script instead of doing it manually, wanna use standard init.d with my processes – Eki Eqbal Nov 06 '12 at 14:04
  • But, wait, monit can start your programs for you. Why do you want a separate init.d file? – Sergio Tulentsev Nov 06 '12 at 14:07
  • cuz monit require me to specify PID file and start and stop location for the service which is what init.d exactly does, remember i'm using ruby processes rather than a rails, so this way I will need do all that manually, actually forman seems doing great job just to do so for upstart and inittab but not for init.d http://blog.daviddollar.org/2011/05/06/introducing-foreman.html – Eki Eqbal Nov 06 '12 at 14:11
  • Ok, I got you, In this case, upstart and inittab are not available on your system, I take it? Good luck with your problem, anyway :) – Sergio Tulentsev Nov 06 '12 at 14:19
  • :( thanks for your willing to help here .. – Eki Eqbal Nov 06 '12 at 14:20
  • Is there any reason you can't use Upstart? – Dogbert Nov 06 '12 at 14:22
  • cuz I'm using init.d in my production server and I don't wanna risk it by changing that, ubuntu 11.01 already shipped with it and i've been using it for long time now – Eki Eqbal Nov 06 '12 at 14:25

2 Answers2

1

mm it seems no tool to create that , foreman can export inittabs, upstart but not init.d, the only way is to modify the file :

/etc/init.d/skeleton 

You will need to slightly modify it, and then :

chmod +x /etc/init.d/process_name 
sudo update-rc.d process_name defaults
sudo /etc/init.d/process_name (start| stop| reload ) 

Done . :)

Eki Eqbal
  • 5,779
  • 9
  • 47
  • 81
0

Another Answer could be with using https://github.com/ghazel/daemons gem .

require 'daemons'
require 'process'

Daemons.run('process.rb')

Once the script is done, just call it from your command line:

ruby process.rb run|start|stop|restart

This config will generate a "process.pid" file under "/var/run" and you can use monit to watch over the process by using this file.

Eki Eqbal
  • 5,779
  • 9
  • 47
  • 81