I wonder what's the better practice to run rails server with Puma and nginx on reboot.
because my crontab doesn't work.
I want to learn how to run the server automatically in other ways
PATH=/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/home/userA/bin:/home/userA/.rbenv/shims:/home/userA/.rbenv/bin:/home/userA/.rbenv$
SHELL=/usr/bin/zsh
#reboot zsh -l -c 'cd /project && bundle exec puma config/puma.rb'
Related
I try to run sidekiq service with supervisord
Here's my config:
[program:my-app-sidekiq-staging]
directory=/srv/www/DOMAIN/current
command=RAILS_ENV=production /usr/local/rvm/bin/rvm ruby-2.2.2#my-app-staging do bundle exec sidekiq -e production -d -C config/sidekiq.yml -L log/sidekiq.log
autostart=true
autorestart=true
redirect_stderr=true
After startup I’m have fatal error:
can't find command 'RAILS_ENV=production'
I’m confused, because my config for rails runs without errors
directory=/srv/www/DOMAIN/current
command=RAILS_ENV=production /usr/local/rvm/bin/rvm ruby-2.2.2#my-app-staging do bundle exec passenger start -S tmp/unicorn/ilp-app-unicorn.sock --environment production --friendly-error-pages
Your environment should not be set in the command but in a separate environment value.
environment=RAILS_ENV=production
See this question.
Supervisor and Environment Variables
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!
In Ubuntu, I can run a rails server in the background as a daemon by passing in the --daemon option;
bundle exec puma -e production -b unix:///var/run/my_app.sock --daemon
However, how do I gracefully shut this daemonized process down? It's not a simple matter of crtl + c anymore :)
It is better to use puma control pumactl, it processes monitor and controller.
and then you can use it like this to stop
bundle exec pumactl -P /var/run/puma.pid stop
OR
pumactl -C unix://var/run/my_app_pumactl.sock [status|restart|halt|stop]
I am running my rails application using ruby enterprise edition with unicorn as app server. I run this command
bundle exec unicorn -D -c /home/ubuntu/apps/st/config/unicorn.rb
I need to run this command soon after the system reboots or starts. I am running the app on ubuntu 10.04 LTS EC2 instance. I tried couple of examples which are mentioned on this site as well as this site but it’s not working for me. Any heads up
Try it as an Upstart. To do so, you need to create a myapp.conf file into the directory /etc/init/ with the contents below:
description "myapp server"
start on runlevel [23]
stop on shutdown
exec sudo -u myuser sh -c "cd /path/to/my/app && bundle exec unicorn -D -c /home/ubuntu/apps/st/config/unicorn.rb"
respawn
After that, you should be able to start/stop/restart your app with the commands below:
start myapp
stop myapp
restart myapp
Use ps -aux | grep myapp to check if your app is running.
You can use this file as a template, set appropriate paths mentioned in this file, make it executable and symlink into /etc/init.d/my_unicorn_server. Now you can start the server using:
sudo service my_unicorn_server start
Then you can do:
sudo update-rc.d my_unicorn_server defaults
To startup the unicorn server on system reboot automatically.
In my case, I just wanted it quick so I place the startup command in /etc/rc.local like below. Note that i'm using RVM.
# By default this script does nothing.
cd <your project dir>
/usr/local/rvm/gems/ruby-2.2.1/wrappers/bundle exec unicorn -c <your project dir>/config/unicorn.conf -D
test -e /etc/ssh/ssh_host_dsa_key || dpkg-reconfigure openssh-server
exit 0
Make sure your startup command is above the exit 0. After you reboot, check whether it is running or not by directly hitting the url of your application or use ps -aux | grep unicorn command.
Note* Previously I use Phusion Passenger but I'm having trouble to see its error log, so I move back to unicorn. I also tried #warantesbr without success, which I guess it fails because my whole environment where setup using root access.
If you are using unicorn_init script
You can configure a cron job to start the unicorn server on reboot
crontab -e
and add
#reboot /bin/bash -l -c 'service unicorn_<your service name> start >> /<path to log file>/cron.log 2>&1'
I'm trying to start my Rails app with thin from the shell script. If I run the commands manually, everything works fine, but if I run the script, it just won't work.
#!/bin/bash
cd /path/to/my/project_1
thin -e production -p 3000 --daemonize -s 10 start
cd /path/to/my/project_2
thin -e production -p 3010 --daemonize -s 10 start
What am I doing wrong? Thanks.
This question was solved in the comments, but for posterity’s sake:
Make sure you have execute permission on the script. chmod 755 my_awesome_script ought to do it.