Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UNIX Ruby scripts on startup

Tags:

unix

ruby

startup

I have three different scripts that I'd like to run on startup - currently I'm running them via:

nohup ruby script1.rb & disown

I can't seem to find how to run each of these scripts on startup, i.e. if the server happens to reboot.

/usr/bin/ruby
/usr/bin/gem

Distribution: Debian

like image 611
user3888415 Avatar asked Feb 24 '26 12:02

user3888415


1 Answers

You need to add the shebang line to your script:

#!/usr/bin/env ruby

and them make you script executable

chmod +x great_script.rb

and then use it with full path, like this

/home/user/bin/great_script.rb

Also you could add your scripts folders to path:

export PATH=/home/user/bin:$PATH

Since you don't mention your distribuition, you need to check how can you add a script to the startup system manager, although following what I've posted you are able to run Ruby scripts like any regular bash script.

UPDATE

In debian, according to the documentation

  1. copy your file to /etc/init.d/
  2. as root run: update-rc.d great_script.rb defaults
like image 177
Paulo Fidalgo Avatar answered Feb 26 '26 09:02

Paulo Fidalgo