If I run my script manually, i.e. sh /home/deploy/scripts/cleanup.sh, everything works fine, but when executing the same script via crontab, the delayed_job part does not work (everything else works!)
# Restart all processes
cd ~/apps/kosher/current
~/.rvm/bin/rvm default do bundle exec pumactl -S /home/deploy/apps/kosher/shared/tmp/pids/puma.state -F /home/deploy/apps/kosher/shared/puma.rb stop
~/.rvm/bin/rvm default do bundle exec puma -C /home/deploy/apps/kosher/shared/puma.rb --daemon
if RAILS_ENV=production bin/delayed_job restart
then
echo "kosher delayed_job restarted" >> /home/deploy/scripts/cleanup.log
else
echo "kosher delayed_job restart failed" >> /home/deploy/scripts/cleanup.log
fi
I tried to use ~/.rvm/bin/rvm default do bundle exec bin/delayed_job -n 1 restart instead of RAILS_ENV=production bin/delayed_job restart, but then I receive an error, stating, that I'm missing the listen-gem:
bundler: failed to load command: bin/delayed_job (bin/delayed_job)
LoadError: Could not load the 'listen' gem. Add `gem 'listen'` to the development group of your Gemfile
However, my Gemfile does indeed include the gem.
Why can't I restart delayed_job via crontab?
Related
I am trying to install a RoR server on Amazon EC2 using Amazon Linux and Ansible. Everything goes through fine, at the end I am not able to run unicorn. I have checked that unicorn gem is installed
`gem list | grep unicorn`
showed unicorn installed.
When I type
`unicorn_rails`
I get command not found error. I checked my gem file and it has the line gem unicorn then I run bundle install and the output has unicorn in the list. Still not able to run it.
Thanks.
I'm not sure that you can run unicorn_rails. Just use:
bundle exec unicorn -p <port> -c <path_to_config_file>
For example:
bundle exec unicorn -p 3000 -c ./config/unicorn.rb
If you are using bundler run unicorn with bundle exec:
$ bundle exec unicorn_rails
Find out more here.
I added those rows to /home/web/.bash_profile. The web is the user of Rails app.
SECRET_KEY_BASE=xxxxxxxxxxxxxxxxxxxxx
export SECRET_KEY_BASE
I added this row into /etc/sudoers.
Defaults env_keep += "SECRET_KEY_BASE"
This command returns expected result.
sudo ruby -e 'puts ENV["SECRET_KEY_BASE"]'
If I run Unicorn without God, it can find SECRET_KEY_BASE from environment, and performs normally.
bundle exec unicorn_rails -c config/unicorn.rb -E production -D
Running Unicorn using sudo without God performs normally, too.
sudo bundle exec unicorn_rails -c config/unicorn.rb -E production -D
But when I run Unicorn with God using sudo, it failed to find SECRET_KEY_BASE and becomes error.
sudo god start my_app
The start command in the my_app.god is this.
God.watch do |w|
w.start = "cd #{rails_root} && bundle exec unicorn_rails -c config/unicorn.rb -E #{rails_env} -D"
w.uid = 'web'
w.gid = 'web'
...
end
It seems that the problem exists around God rather than .bash_profile and Unicorn. Besides what should I try?
I added this line into the my_app.god
ENV["SECRET_KEY_BASE"] = 'xxxxxxxxxxxxxxxxxxxxxxxx'
I know that this isn't a cool solution, but it works. And SECRET_KEY_BASE isn't included in a Git repository as source code.
Rails 3.2.18
Ruby 2.1.5
Capistrano
Apache2
Phusion Passenger
Ubuntu 14.04.2
I have been using Capistrano to deploy my application. The set of commands that Capistrano executes (after connecting to the repo and copying all the files):
cd /home/myapp/current
RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile
cp /home/myapp/shared/assets/manifest.yml /home/myapp/current/assets_manifest.yml
touch /home/myapp/current/tmp/restart.txt
echo \"DEPLOY SIDEKIQ RELOAD $(date)\" >> /home/myapp/current/log/sidekiq.log
screen -d -m sh -c 'cd /home/myapp/current && RAILS_ENV=production bundle exec sidekiq'
cd /home/myapp/current && RAILS_ENV=production bundle exec rake sunspot:solr:stop
cd /home/myapp/current && RAILS_ENV=production bundle exec rake sunspot:solr:start
screen -d -m sh -c 'cd /home/myapp/current && RAILS_ENV=production bundle exec rake sunspot:solr:reindex'
Recently, following a deployment, instead going into the web application, when I enter the URL, all I see is a directory listing of the /home/myapp/current/public in my browser.
I can start the application manually by doing:
cd ~/current
sudo service apache2 stop
rvmsudo bundle exec rails s -e production -p 80 -d
The problem here is that some of the Rails app tasks start running as root (writing files, files uploaded, etc), which is problematic and is probably a security risk. Any ideas?
Here is what I am running:
rbenv sudo foreman export upstart /etc/init -a myapp -p 8080 -u myuser
What gets generated in ...web-1.conf
start on starting myapp-web
stop on stopping myapp-web
respawn
exec su - myuser -c 'cd /home/myuser/apps/myapp; export PORT=8080; bundle exec unicorn -p $PORT -c ./config/unicorn.rb >> /var/log/myapp/web-1.log 2>&1'
When I run tail -f /var/log/myapp/web-1.log, I see the following:
-su: bundle: command not found
It appears $PATH is being reset. If I manually cd into that directory, while running under myuser, I can execute the command just fine. Thoughts?
I am using foreman, rbenv, rbenv-sudo, unicorn, rails 4.0.0, and ruby 2.0.0-p247.
Thanks!
Okay, so I had my rbenv being configured in ~/.bashrc.
su - myuser -c is a login shell, but not an interactive shell.
I moved rbenv config to ~/.profile and everything seems to be working now.
Thanks!
Using Foreman on my rails application with Ruby 1.9.3 just fine. Switched to JRuby and now, as an example, get :
18:22:16 solr.1 | /home/scott/.rvm/gems/jruby-1.6.8#jruby168-unicon/gems/foreman-0.47.0/bin/foreman-runner: 32: exec: bundle exec rake sunspot:solr:run: not found
When I run bundle exec rake sunspot:solr:run on its own on the command line it runs just fine
Procfile:
web: puma
solr: bundle exec rake sunspot:solr:run
redis: redis-server ./config/redis.conf
sidekiq: bundle exec sidekiq -c $SIDEKIQ_CONCURRENCY -q report -q publish_item -q audio -q import -q email -q enrollment -q bugsnag
bunchball: bundle exec sidekiq -c 2 -q bunchball
sidekiq_solr: bundle exec sidekiq -c 1 -q solr
You have install bundler in Jruby.
gem install bundler