Reputation:
I have got this funny constraint on a Redat 5.8 from our offshore IT team.
I have not been granted sudo or root user access. my current user has limited capabilities.
I have successfully install all dependencies for my rails application to run but now I need to ensure that each time the server restart arbitrarily that the application restarts automatically.
I have a script to do this for apache and mysql below and these work very well.
* * * * * /bin/netstat -ln | /bin/grep ":8080" | /usr/bin/wc -l | /bin/awk '{if ($1 == 0) system("/path/packages/apache/bin/apachectl start") }'
* * * * * /bin/netstat -ln | /bin/grep ":3306" | /usr/bin/wc -l | /bin/awk '{if ($1 == 0) system(""/path/to/mysql/support-files/mysql.server start") }'
But here following the same pattern for starting my rails application using unicorn. it just does not work.
* * * * * /bin/netstat -ln | /bin/grep ":3000" | /usr/bin/wc -l | /bin/awk '{if ($1 == 0) system(" /bin/cd /path/to//current/; RAILS_ENV=production./bin/unicorn -D -E $RAILS_ENV -p 3000 -c ./config/unicorn.rb 2>&1 >> ~/log.log")}';
The above does not seem to get my rails application started.
I need help with this.
Upvotes: 0
Views: 126
Reputation:
We finally got my head around it.
The error we found had to good with bundle/setup (Loadfile error)
All that is require to properly setup the Environment variables to using rvm's cron feature
Found here https://rvm.io/integration/cron
By running this command on the terminal it setup the right environment varaiables.
rvm cron setup
This adds the PATH, GEM_HOME etc etc at the top of the crontab.
With this in place we could then start ruby from crontab
I just want to say thanks to steve and holger.
Upvotes: 0
Reputation: 28402
Within your command above
* * * * * /bin/netstat -ln | /bin/grep ":3000" | /usr/bin/wc -l | /bin/awk '{if ($1 == 0) system(" /bin/cd /path/to//current/; RAILS_ENV=production./bin/unicorn -D -E $RAILS_ENV -p 3000 -c ./config/unicorn.rb 2>&1 >> ~/log.log")}';
Change the
RAILS_ENV=production./bin/unicorn
to
RAILS_ENV=production;/bin/unicorn
If this does not fix the problem then look in the mail for the user running cron or in the log file log.log and see whether that provides any clues
Upvotes: 1