aws.push command not running .config commands or container_commands - ruby-on-rails

I have a simple setup with a load-balanced application and want to run some commands for cron setups (for instance, using the whenever gem). However, none of my commands seem to get run on the remote server.
# .elasticbeanstalk/Production.config
container_commands:
20_update_crontab:
command: whenever --update-crontab app
leader_only: true
Even tried:
# .elasticbeanstalk/Production.config
commands:
update_crontab:
command: whenever --update-crontab app
Is there something I am missing? These should run with git aws.push correct?
When I check the logs, I don't really get any information saying it was trying to run:
$ eb logs | grep whenever
Using whenever (0.9.2)
The descriptions on this page are pretty good, just can't figure out why it isn't running.
http://www.infoq.com/news/2012/11/elastic-beanstalk-config-files

Elastic Beanstalk configuration files should be placed in .ebextenstions/. It looks like yours are in .elasticbeanstalk/
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers.html
Create a configuration file with the extension .config (e.g., myapp.config) and place it in an .ebextensions top-level directory of your source bundle.

I had a similar problem where I was trying to install libjpeg for my EC2 instance using the configuration files and it was never installed. I tried everything and was never able to find a "good solution", but I did solve it though.
Solution:
How to solve it? Set up a completely new Elastic Beanstalk Application and deploy the same app again. After I did this it worked from the start with the new EB App.
Check out my other answer here: https://stackoverflow.com/a/23109410/2335675
Check it out, hope it helps for you.

Related

Deploying Ruby on Rails apps to Railway

I hope you are all well!
For several days now I have been trying to deploy a simple rails app to Railway.app, and failing catastrophically and repeatedly to get it to run.
Here is the github repo:
https://github.com/CaffieneSage/blogApp-rails-
The error I am getting is during the deploy step specifically:
bundler: not executable: bin/rails
I have successfully deployed apps to heroku in the past. I suspect there is something simple that I am missing. I have tried rerolling and deploying the default rails app to simplify things. I have made sure to us postgres instead of SQLite3 as the db. I have spun up an instance of postgres on railway and tried to set my environment variables to point to it. I have had a go within the CLI as well.
Thanks in advance for any advice you may have to offer!
This is my first post on stack overflow, please go easy on me ;]
The issue likely stems from the script bin/rails not having the executable bit on the file.
You can see the file permissions using ls:
ls -l bin/
All of the files will display:
-rw-r—r—
These need to have the executable bit set, so you can run something like:
chmod +x bin/*
After which all the files should have this permission set:
-rwxr-xr-x
Don’t forget to commit the changes.
Read more on file permissions: https://en.wikipedia.org/wiki/File-system_permissions

Why Rails 4.2 app create log files with root permissions when deploy it on Ubuntu server using Ansible during running rake db:migrate task

Scope of problem
Rails 4.2.11
Ansible 2.1.1.0
Ubuntu 14
Ubuntu user: deploy
I have Rails app which I deploy to Ubuntu server by Ansible script.
I have problem of understanding why Rails app create log files with root permissions when Ansible script execute rake tasks.
In my example it's running rake db:migrate but also same behaviour with rake assets:precompile
You can see by photo below that application is deployed via user 'deploy' but after run of rake task it create 2 log files with root permission. After restart of web server it crash with permission denied error, so I need manually change ownership to deploy:deploy
Structure of Rails logger is also looks suspicious. You can check #dev=IO:<STDERR> value. I've checked in another project and there I can see something like #dev=#<File:/var/www/.../log/production.log>
I tried to explore source code of ror4 but so far no luck to understand from there what is happening. Only idea is could be that Rails raise exception when create log file and STDERR become output
Please help if you have similar problem or can point out where I can look to.
The rake script runs as root User.
To answer the question you must add the complete ansible script or the bundle script if you manually add a "sudo" commands or something unusual.
There are different possible positions to define the user in ansible.
Read the become section of the ansible documentation https://docs.ansible.com/ansible/latest/user_guide/become.html
Or give a try with
- name: Run db:migrate
shell: ... rake cmd ...
become: yes
become_user: deploy
become_method: su
Change the become_method to your needs e.g become_flags: '-s /bin/sh' or sudo

Booting up Sidekiq with Upstart

My goal is to have sidekiq start when the server boots up (I'm using EC2 with an auto-scaling group). I know there are a few other posts regarding getting sidekiq to start with upstart on boot, but I don't believe mine has been addressed specifically.
I'm using this wiki - https://github.com/mperham/sidekiq/tree/master/examples/upstart/manage-many and have placed the scripts inside /etc/init/sidekiq.conf and /etc/init/sidekiq-manager.conf.
I've made a couple small modifications as directed in /etc/init/sidekiq.conf, changing:
# setuid apps
# setgid apps -> replaced apps with ubuntu in both lines, which is the deployment user.
export HOME=/home/apps to export HOME=/home/ubuntu
I also have a /etc/sidekiq.conf that includes the following line:
/home/ubuntu/app_dir, 2
Otherwise, these scripts are identical to those included in the referenced repo. I'm getting the following errors in my logs (/var/log/upstart)
/bin/bash: line 19: cd: 2: No such file or directory
Could not locate Gemfile
It appears as if it's attempting to change directory somewhere other than /home/ubuntu/app_dir, at which point it's in the wrong directory and cannot find my Gemfile.
Is there somewhere else I need to specify a correct path to my app directory?
Thanks!
You can run sidekiq as an upstart job. Making a sidekiq.conf file in /etc/init/ directory and put the upstart code to run sidekiq.
Here is the complete script and the guide to make sidekiq upstart job.
After making this job, sidekiq start/stop/restart would be easy with sudo service command.

Deploying Ruby on Rails - Is there a good alternative for Heroku? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I'm starting a new small venture, a POC if you would like, and I want to deploy my Rails application for free somewhere.
I found that there is Heroku, are there another options?
Yes there are
This is a very good post I found on the subject
http://blog.sudobits.com/2013/02/15/heroku-alternatives-for-deploying-rails-applications
I went over the options there one by one and, to my humble opinion, OpenShift is the best option for a small-medium website, at least for the beginning of developing and creating a POC\Prototype
Why is it better?
It gives you what Heroku will give you
It give you local (persistant) storage - So you don't need to pay for S3 on Amazon or equivalent - I guess that in some point you would like to do that (to use S3), but at least for the begining you don't need to put money on it
It seems that the website is running faster
I find it more flexible in terms of controlling what is happening on the machine
Are there any disadvantages?
The only disadvantage I could find on Openshift is that it seems that the deployment takes much more time then on Heroku and there is considerable delay on the first time you address the website (But after the first time is working faster - Not related to browser caching if you think this is the issue)
It might be that the Gemfile section under this document https://www.openshift.com/blogs/converting-an-existing-rails-app-to-run-on-openshift can solve this issue...I will try it later
What are the steps I need to do in order to deploy my already existing application on Openshift?
In many places I found explanations about how to create and deploy new application, but it was a little bit hard to understand how to put my already existing application on OpenShift
This is the reason I want to explain that
Assumptions
- Your application is git controlled already
- Its path is /home/dev/MyApp
- you are now under /home/dev
Create Openshift account on https://www.openshift.com
Use the command line tools, I found them much more informative
Go to https://www.openshift.com/get-started
Follow steps 1..3 in order to install and setup the command line tools
cd to your rails application folder /home/dev/MyApp
Create a new application domain - Run : rhc domain-create <domain name>
Create your application in OpenShift by running
rhc app-create -a MyApp -t ruby-1.9 --no-git
-a sets the application name under OpenShift - It can be something totally different from your rails application name
-t sets the application type - I think that for now ruby 1.9 is their highest supported version
--no-git tells not to create git - Because we already got one
Setup your DB
Install the appropriate DB cartridge for your OpenShift application by calling
rhc cartridge add <DB cartridge type> -a <Application Name>
For example :
rhc cartridge add mysql-5.1 -a MyApp
It also supports MongoDB and PostgreSQL
(see here https://www.openshift.com/developers/technologies)
Change your database.yml to relate to the OpenShift database - Now, that is very easy since OpenShift got a lot of its configuration as environment variables and you can simply use it wherever you need - For example :
production:
adapter: mysql
encoding: utf8
database: <%=ENV['OPENSHIFT_APP_NAME']%>
pool: 5
host: <%=ENV['OPENSHIFT_MYSQL_DB_HOST']%>
port: <%=ENV['OPENSHIFT_MYSQL_DB_PORT']%>
username: <%=ENV['OPENSHIFT_MYSQL_DB_USERNAME']%>
password: <%=ENV['OPENSHIFT_MYSQL_DB_PASSWORD']%>
socket: <%=ENV['OPENSHIFT_MYSQL_DB_SOCKET']%>
Make sure everything is working locally
Run : 'bundle install'
Run : 'rails s' - See that everything is OK
Git - Add the OpenShift repository as one of your remote repositories and push it
Make sure all your work is updated , commited and syncronized with your GitHub - This can save a lot of headach later
Run : rhc app-show <application name> - This will show you all the information about your application - Copy the Git URL
Run : git remote add openshift <OpenShift repo URL>
Take whatever OpenShift is adding by merging
Run : git merge openshift/master -s recursive -X ours
Commit the changes : git commit -am 'adding OpenShift files
Push to OpenShift : git push openshift
That is all , now your application should be deployed on OpenShift
How do I open my deployed web site?
Using the rhc app-show <application name> command you can see your website url
It will usually be http://<application name>-<domain name>.rhcloud.com
It is quite easy to change it to your own domain
Just run rhc alias add <app name> <your domain>
Then in your DNS management - Edit the CNAME 'www' definition to point to
http://<application name>-<domain name>.rhcloud.com
How do I connect to my OpenShift machine?
Again , using rhc app-show <application name> you can see the SSH address
Simply run ssh <SSH address> in order to connect
How do I run the migrate and seed automatically upon deployment?
One nice thing in OpenShift is the ability to add custom actions (action-hooks) that are being triggered in different stages of the deployment
You can read more about it here https://www.openshift.com/developers/deploying-and-building-applications
For now, I will only talk about the deploy action-hook
Under your application folder go to .openshift/action_hooks and create a file named deploy under it
Make this file executable - Run : chmod +x deploy
Put some code into it
For example:
#!/bin/bash
echo "Starting deploy"
pushd ${OPENSHIFT_REPO_DIR} > /dev/null
echo "Change directory to ${OPENSHIFT_REPO_DIR}public"
cd ${OPENSHIFT_REPO_DIR}
cd public
echo "Creating soft link to ${OPENSHIFT_DATA_DIR}uploads named uploads"
ln -s ${OPENSHIFT_DATA_DIR}uploads uploads
echo "Running bundle exec rake db:migrate RAILS_ENV=production"
bundle exec rake db:migrate RAILS_ENV="production"
echo "Running bundle exec rake db:seed RAILS_ENV=production"
bundle exec rake db:seed RAILS_ENV="production"
popd > /dev/null
The soft link will be explained later - it is needed for the routing to find the Carrierwave uploaded files
Add the file to your git - git add deploy (from inside the folder of course)
Commit your changes and push to openshift remote
How can I integrate Carrierwave so I could upload files and save on OpenShift?
There are two points
Where will the files be saved ? - This is easy
Will the routing know how to fetch my uploaded files ?
Setting the saving path:
Set the initializers\carrierwave.rb file to be
CarrierWave.configure do |config|
if Rails.env.production?
config.storage = :file
config.enable_processing = true
config.root = ENV['OPENSHIFT_DATA_DIR']
config.cache_dir = config.root + 'uploads'
end
end
leave the uploaders as they are by default, meaning storage :file
and
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
The use of the $OPENSHIFT_DATA_DIR folder will make sure we will be able to write the files and that it will stay there
Making sure the routing will find the files:
It took me a while to come up with that trick (not too much, just a couple of hours)
Rails routing knows how to relate only the the folders that are under the application folder - soo, on OpenShift machine, it will look for the uploaded files folder (named uploads in our case) under the ${OPENSHIFT_REPO_DIR}\public folder , this is where the soft link I put in the deploy file is becoming handy - It simply cheats the system and making it to go and fetch those file from a folder which is not under the application folder
I know there are a lot of posts about those issues and how to deploy and everything, but I just wanted to put some order into it.
Of course there might be mistakes and inaccuracies in what I wrote since I didn't documented every step of the way but just from what I remember, feel free to correct me if I'm wrong in some details.
One of the best sourced is the OpenShift documentation
I hope those things will help people and save you time and money
Enjoy

Cap deploy hangs at initial clone

During the initial deployment, cap deploy hangs at the initial clone. It gives this output and sits there forever, without exiting or giving any kind of error:
** [50.18.125.107 :: out] Cloning into 'home/torquebox/apps/releases/20120808033824'...
It is similar to this question, except I'm able to execute the command manually, just not automate it with capistrano.
Server setup:
Ubuntu 12.04 LTS on EC2
TorqueBox server, jruby, java6, postgresql, mysql, apache2, tomcat7
Dev machine:
OSX Lion
Using the ssh keys on my dev machine to access github via forward_agent
Application:
JRuby on Rails
github repo
deploy.rb in a gist
The facts and what I have tried:
cap deploy:setup works fine and does create the directory structure.
if I ssh in manually and execute the commands, the clone works correctly.
I've tried cap with verbose (-v) and debug (-d) and neither gave me any more info.
I tried to ssh into github using the forward_agent on the remote machine to deal with the known hosts bug but thatworked fine too.
I checked the environment variables and realized that not everything was getting loaded because it's not an interactive shell, so I added the additional PATH dirs and other environment variables that are usually loaded by login scripts. I even edited the sshd_config file to allow user environments in non-interactive scripts.
I tried executing the commands manually via cap shell but I'm seeing the same behavior.
The clone operation does create the correct target directory and put a .git directory in it, but the repo seems empty.
I've tried with the remote-cache option on and off, and see the same behavior either way.
I tried using the ec2 dns name for my server rather than the elastic IP, because of this post but that didn't work.
So I'm stuck. I'd really appreciate any suggestions of where to look next to try to figure this out. Let me know if any more info would be helpful.
Thanks!!
Will
The issue is probably the fact that ssh agent forwarding is broken in JRuby. It is fixed as of JRuby 1.7.0.pre2.
see: http://jira.codehaus.org/browse/JRUBY-6181

Resources