Monit start without sudo on starting unicorn - ruby-on-rails

I am using monit at production server. I have installed rbenv and bundler in a user which is in sudo group. Monit is unable to start unicorn server because it uses sudo by default and bundle command is not present in sudo.
`$ /etc/init.d/unicorn_demo_app start`
is working fine. When I say
`$ sudo /etc/init.d/unicorn_demo_app start`
Giving error as su: bundle command not found.
So monit using sudo to start the unicorn server. How can I make Monit NOT TO use sudo.?

Have you tried to reinstall rbenv and bundler with standard user?

binstubs will solve your problem. the rbenv docs go into it pretty well https://github.com/sstephenson/rbenv/wiki/Understanding-binstubs

Related

quickly starting up a rails app on a new server; "No command 'puma' found"

I am trying to quickly set up a rails server. I have an app that I have working an running on my personal computer. Running rails server launches it in localhost:3000 with no issues.
I am trying to start a server on a server to an external IP. So, I followed the instructions here: http://luugiathuy.com/2014/11/setup-nginx-puma-on-ubuntu/ with no issue until I ran: puma -e production -d -b unix:///tmp/app_name.sock --pidfile /tmp/puma.pid and got:
No command 'puma' found, did you mean:
Command 'pump' from package 'pump' (universe)
Command 'pumpa' from package 'pumpa' (universe)
Command 'duma' from package 'duma' (universe)
I have run: gem install puma and bundle install I have added gem 'puma' to my gemfile.
If I visit the external IP of the server I get the nginx error of:
We're sorry, but something went wrong.
If you are the application owner check the logs for more information.
which makes sense since puma isn't running.
Solved it:
`/bin/bash --login`
I believe this worked because before I was not "logged in" to the user that had puma installed

bundle exec rake db:migrate says Run `bundle install`

bundle install
This works perfectly fine. But when I do
bundle exec rake db:migrate
It says
Could not find byebug-6.0.2 in any of the sources
Run `bundle install` to install missing gems.
From comments, I saw that you use 2 different types of commands, 1 with sudo and 1 without.
Problem is: sudo is another user (root user), so what you install by sudo may not be applied for other users and vice versa.
The solution I could think of is to use all sudo commands, since your current user seems not to have access to PG.
sudo bundle install
sudo bundle exec rake db:migrate
I just troubleshat this same problem. I finally tried removing byebug and was offered a choice of byebug_6.0.2 or byebug_8.1.0. Removing the earlier version didn’t do it so I removed the other as well. I then reinstalled using
gem install byebug
That gave me another failed migrate, this time blaming debug_inspector. I ran
gem install debug_inspector
After that I was able to run rake db:migrate as expected.

Sudo Access to Rails gem installed from Github

I am required to run the following Ubuntu bash script as "sudo" (FYI, this is because I am running it through Upstart):
cd /u/apps/MyRailsApp/current && /usr/bin/env RAILS_ENV=production script/delayed_job restart >> /var/log/upstart/delayed_job.log
However, when I run it as "sudo", I get the following error:
/var/lib/gems/1.9.1/gems/bundler-1.7.6/lib/bundler/source/git.rb:188:in rescue in load_spec_files': git#github.com:MyRemoteRepo/my_gem.git (at 1.0.1) is not yet checked out. Runbundle install` first. (Bundler::GitError)
It's not recommended to run "bundle install" as Sudo. When I run "bundle install" as a non-admin user, it is working and all the gems are recognized. How do I get the root user to recognize the gem?
The gem is in /home/ubuntu/.bundler/ruby/1.9.1/. My other gems are in /var/lib/gems/1.9.1/gems/
Thanks so much for your help.
Try adding "source /home/[username]/.bashrc" where [username] is non-admin user that can run the script successfully.

foreman start fails with error "Please install daemon_controller first:"

I want to monitor my app with upstart. I'm exporting using
rvmsudo foreman export upstart /etc/init -a <my_app_name> -u ubuntu -l /var/<my_app_name>/log
It finishes successfully, but when i do
sudo start <my_app_name>
I get the following output and nothing happens
<my_app_name> start/running
my procfile
web: rvmsudo passenger start -p80 -e production
worker: rvmsudo bundle exec rake jobs:work RAILS_ENV=production
Its really frustrating because i can run the web and worker commands on different terminals individually. So I tried to just do a foreman start and this fails with the following error
*** ERROR ***
Please install daemon_controller first:
/usr/local/rvm/gems/ruby-2.0.0-p594/wrappers/gem install daemon_controller
The frustrating bit is that daemon controller is installed and i can see it when i do gem list
Maybe my whole approach to this is wrong can someone please point me in the right direction?
Here's the line in passenger that returns that error, so it looks as though it really can't find daemon_controller as it's rescuing a LoadError. Try updating your web process to run via bundle exec also:
web: rvmsudo bundle exec passenger start -p80 -e production

Ruby On Rails Database

Whenever I run the command rvmsudo rake db:migrate (I need to use rvmsudo because I'm using rvm), the sqlite3 files generated are owned by root.
ls -l db/*.sqlite3
Because of this, I keep on getting a SQLite3 Read Only Error whenever I try to do anything to the database, and I have to manually enter the command:
sudo chown -R myusername db/*.sqlite3
rvmsudo rake db:migrate never did this before, and I am wondering why it is happening now.
Did you install RVM as root, and if so, is there a reason it wasn't installed as your normal (less-privileged) user? I use RVM daily, on a number of machines, and haven't had to install RVM as root.

Resources