Starting god as deploy user - ruby-on-rails

I have an init.d script to start up god on my server after a reboot.
I've run sudo chmod +x /etc/init.d/god and sudo update-rc.d -f god defaults and when I run /etc/init.d/god start as the deploy user I have no issues and god starts.
However, when I reboot the server god doesn't start.
When I try and start god manually as root I get this error:
Your Ruby version is 1.9.3, but your Gemfile specified 2.3.0
I believe the issue is something to do with root not having rvm or ruby 2.3.0. Is there a way to run the init.d script as deploy?
I'm on Ubuntu 14.04, ruby 2.3.0 and god 0.13.7

You can run any command (or execute a script) as any user with the sudo command; just use the -u flag to specify the user. Example:
sudo -u deploy /etc/init.d/god
See more here: http://www.sudo.ws/man/1.8.15/sudo.man.html

Related

Docker - Error response from daemon: client is newer than server

After creating a new machine with Docker Machine, I'm getting the following error:
$ docker ps
Error response from daemon: client is newer than server(client API version 1.21, server API version: 1.19)
How can I fix this?
docker-machine upgrade <your-machine>
will do the trick. This can happen - as it did for me - even if you're not using RCs and your machine was newly created. It would be due to an ISO cache issue. The error is commented in this thread.
If the docker client is 1.9.x and the server is running docker 1.8.x,
the error message is observed.
If someone happens to get this error, but is not using docker-machine, there is another way to resolve the issue by specifying an older API version in an environment variable on the client side:
export DOCKER_API_VERSION=<version>
for example:
export DOCKER_API_VERSION=1.19
and retrying the docker command.
Reference.
On ubuntu distrib it happens after an apt update, if docker run as a service.
The client is updated but the old version of the server is still running.
In this case just do a:
sudo service docker restart
If you upgrade your docker client you will not be able to use old docker-machine VMs. Actually you can force an upgrade with docker-machine upgrade vm-name, but if you are working with other distros (except boot2docker) as docker host like coreos, atomic, rancheros it may fail.
I am using Carina to manage more than one docker client version.
just install with $ curl -sL https://download.getcarina.com/dvm/latest/install.sh | sh
(linux and mac installation) and run dvm ls to list installed versions, dvm install 1.9.0 to install versions and dvm use 1.8.1 to change your client version.
Very easy and powerfull. =)
Atention, for your safety always take a look inside scripts downloaded from internet before running them.
Hope it helps
Apparently this error is due to docker-machine "falling asleep". Here is the magic command solving it for me:
$ docker-machine restart default
Or replace default by the name of your machine.
The result is:
$ docker-machine restart default
Restarting "default"...
Restarted machines may have new IP addresses. You may need to re-run the `docker-machine env` command.
As suggested, you may need to:
$ docker-machine env default
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://....."
export DOCKER_CERT_PATH=".../.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"
# Run this command to configure your shell:
# eval $(docker-machine env default)
And so you finally run that command:
$ eval $(docker-machine env default)
From now it should work.
I had the same issue with 1.10.0-rc4, and it turned out that boot2docker wasn't updated properly when installing a newer Docker Toolbox. I had to remove boot2docker manually:
sudo rm -rf /usr/local/share/boot2docker
You can also delete the rest of the toolbox:
sudo rm -rf /usr/local/bin/docker*
sudo rm -rf /Applications/Docker
And finally install Docker Toolbox of the desired version.
Please see official uninstall script for on GitHub for OS X here.

How to start on booting "rvmsudo rails server" command

I am trying to configure my own "Thingspeak" server on Ubuntu 12.04 LTS virtual machine. I introduced this commands on terminal (installation on clean install of ubuntu): https://github.com/iobridge/ThingSpeak but at the final I use:
rvmsudo rails server -d -b <myip> -p 80
This command let me run Thingspeak app on port 80 as a daemon. It works well, but when the server reboot (sudo reboot for example) the thingspeak server shut down and I don't want this, I want to automatically (on booting or startup) start the thingspeak server so I don't need to manually use in terminal the rvmsudo command again.
How can I achieve this?
You can add to:
/etc/rc.local
rvmsudo rails server -d -b -p 80
or add it to /etc/init.d as well
Updating this:
sudo nano /etc/rc.local
Add the following before the exit 0 line:
cd <folder path>
rvmsudo rails server -d -b -p 80

start unicorn app server when the ubuntu server starts

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'

Using $ sudo bundle exec ... raises 'bundle: command not found' error

I have installed rbenv on an Ubuntu sever. I can cd into my application directory and run $ bundle without issue, however I need to run $ sudo bundle exec ... and this gets me an error:
bundle: command not found
Why is this and how can I fix it?
Not entirely sure, but maybe this would work for you:
sudo -i -u $USER bundle exec...
or
sudo -i -u username_with_correct_env bundle exec...
Dan Carley's rbenv-sudo looks like it will do what you want:
rbenv-sudo is a plugin for rbenv that allows you to run rbenv-provided Rubies and Gems from within a sudo session.
A more detailed explanation of how it works is provided in this article: Sudo Rbenv Me a Sandwich
Why you get the error has been addressed already. But I was able to get around it by saying:
sudo /full/path/to/bundle exec ...
In my case, I'm using rbenv, so I had to:
sudo /home/renier/.rbenv/shims/bundle exec ...
That worked. To get sudo to not ask for a password, you would need to configure your /etc/sudoers file for this. See https://serverfault.com/a/160587.
To do this without using rbenv or rvm, do this:
sudo -E bundle exec ...
-E The -E (preserve environment) option will override the env_reset option in sudoers(5). It is only available when
either the matching command has the SETENV tag or the setenv option is set in sudoers(5). sudo will return an error
if the -E option is specified and the user does not have permission to preserve the environment.

How to Uninstall Nginx from Ubuntu 12.04 and Recover Apache

I have Installed Ruby,Rails in my Laptop , I'm Not familiar with Ubuntu, when I install Ruby an Nginx also installed without my permission, Im a PHP programmer now my apache overwritten by Nginx , plz help me
The nginx installation should not overwrite any apache files. I bet you just have to stop it and start apache.
Stop nginx
/usr/bin/nginx -s stop
Start apache
sudo /etc/init.d/apache2 start
You can also use restart and stop instead of start
Make shure the
apache2/conf/httpd.conf
file is correct
To uninstall nginx
sudo rm -f -R /usr/local/nginx && rm -f /usr/local/sbin/nginx

Resources