Problems with starling/workling in production mode - ruby-on-rails

I have a rails app that has asynchronous processing, and I'm having trouble getting it to work in production mode. I start starling from the root of the application like so:
starling -d -P tmp/pids/starling.pid -q log/
then I start workling like this
./script/workling_client start -t
the first time I ran this, it complained because there was no development database, so I created a development database, and that error went away when I restarted workling.
but when I try to actually run an asynchronous process, I get this message in log/production.log
Workling::QueueserverNotFoundError (config/workling.yml configured to connect to queue server on localhost:15151 for this environment. could not connect to queue server on this host:port. for starling users: pass starling the port with -p flag when starting it.
so, I run
sudo killall starling
then restart starling from the root of the application like this:
starling -d -P tmp/pids/starling.pid -q log/ -p 15151
which seems to work fine, but then when I try to start workling again with this script/workling_client start -t, I get this message in the console
/var/rails-apps/daisi/vendor/plugins/workling/lib/workling/clients/memcache_queue_client.rb:68:in `raise_unless_connected!': config/workling.yml configured to connect to queue server on localhost:22122 for this environment. could not connect to queue server on this host:port. for starling users: pass starling the port with -p flag when starting it. If you don't want to use Starling, then explicitly set Workling::Remote.dispatcher (see README for an example) (Workling::QueueserverNotFoundError)
So, I tried changing the config/workling.yml file inside the workling plugin to make both production and development listen on 15151, that didn't work, then I tried both of them on 22122, still no dice, so I tried a random port, but it still gives the exact same behaviour no matter what I put in the workling.yml file

the answer is that starling has to be started as such:
RAILS_ENV=production ./script/workling_client start -t

Related

EC2 : Rails deployment gives blank pages

I have deployed my rails application on EC2. It runs on two servers. One for rails application and second for DB.
When I start application using "rails s -e production&" and if I stay connected using SSH,
I can see the webpages.
As soon as I disconnect SSH I can not see the pages.
There are no errors thrown. One weird thing is "Production.log" file does not have anything.
everything is spit out on console.
You are running rails in the current ssh session. Any programs you have running during that session will stop if you disconnect. You need to set up your rails app to run as a daemon using something like Phusion Passenger.
You are basically running the built in WEBrick server that is not really meant for production so it's likely that the process is getting killed after the parent process (your ssh process) gets terminated.
You can probably tweak the configuration to make WEBrick not quit, or you can simply run your session using screen or tmux
Screen:
$ screen
$ rails s -e production &
$ screen -d
When you want to reattach:
$ screen -r
Tmux:
$ tmux
$ rails s -e production &
$ # Hit <ctrl-b><ctrl-d> to detach
When you want to reattach:
$ screen attach -t 0
Or like #datasage mentioned you can run your Rails with an actual production web server like Passenger Phusion or Unicorn.

cloudcontrol.com tcp port in use & procfile multiple commands & push hooks

i'm trying to get redmine running on cloudcontrol.com. i've got four questions:
i need to do more that start a webserver, for example i need to run rake tasks each time i deploy. can i put those in a one liner? i got the following in my Procfile for testing:
web: touch foobar; echo "barbarz"; bundle exec rails s -p $PORT -e production
but i neither see a file foobar nor do i get barbarz in the log files :(
When i login to the server and want to start the application it tells me tcp $PORT is already in use:
u24293#depvk7jw2mk-24293:~/www$ fuser $PORT/tcp # netstat and lsof is not available
24293/tcp: 10 13
u24293#depvk7jw2mk-24293:~/www$ ps axu | grep 13
u24293 13 0.0 0.0 52036 3268 ? SNs 15:22 0:00 sshd: u24293#pts/0
by sshd??? why would that be?
i need to change this default behaviour during push:
-----> Rails plugin injection
Injecting rails_log_stdout
Injecting rails3_serve_static_assets
or run something after it as easyredmine doesnt like plugins in vendor/plugins (or i cahnge the code of easyredmine quickly). how would i do that (not change the code, run an after hook for that like with capistrano or so)?
we have our own gitlab on a dedicated server and for bundle i need to pull those gems. how can i get the public key of the user running the app before the first deployment so i can add it to gitlab?
thanks in advance :)
The web command is only executed in the web containers. Using run bash connects you to a special ssh container of your app. See https://www.cloudcontrol.com/dev-center/Platform%20Documentation#secure-shell-ssh
Generally, you can not put multiple commands in one Procfile line. Wrap them in a sh -c '<cmd1>; <cmd2>' call or use a shell script explicitly.
Keep in mind that this script will be executed in each container being started. This includes the number of containers you deploy your app with and any redeploys that are triggered by the platform during operation (in case of a node failures, addon changes etc.).
In the ssh container the $PORT is used by the ssh server you are connected to.
If it is a problem of redmine during runtime, you could remove the plugins in the mentioned startup script. If it's a problem during the gem install currently you can not circumvent this behavior.
Dependencies requiring special ssh keys are not supported right now. If your server supports basic auth over https, you can use the https://<username>:<password>#hostname syntax

How to stop (and restart) the Rails Server?

I'm following the instructions here http://railsinstaller.org/mac to get up and running with Rails on a Mac running OS X 10.8.2
At step 8 I'm asked to restart Rails server but how?
I'm assuming via a command line, but from within the already open ruby terminal window or a new one?
Now in rails 5 you can do:
rails restart
The output of rails --tasks:
Restart app by touching tmp/restart.txt
I think that is usefully if you run rails as a demon
Press Ctrl+C
When you start the server it mentions this in the startup text.
On OSX, you can take advantage of the UNIX-like command line - here's what I keep handy in my .bashrc to enable me to more easily restart a server that's running in background (-d) mode (note that you have to be in the Rails root directory when running this):
alias restart_rails='kill -9 `cat tmp/pids/server.pid`; rails server -d'
My initial response to the comment by #zane about how the PID file isn't removed was that it might be behavior dependent on the Rails version or OS type. However, it's also possible that the shell runs the second command (rails server -d) sooner than the kill can actually cause the previous running instance to stop.
So alternatively, kill -9 cat tmp/pids/server.pid && rails server -d might be more robust; or you can specifically run the kill, wait for the tmp/pids folder to empty out, then restart your new server.
In case that doesn't work there is another way that works especially well in Windows: Kill localhost:3000 process from Windows command line
if you are not able to find the rails process to kill it might actually be not running. Delete the tmp folder and its sub-folders from where you are running the rails server and try again.
I had to restart the rails application on the production so I looked for an another answer. I have found it below:
http://wiki.ocssolutions.com/Restarting_a_Rails_Application_Using_Passenger
I just reboot the server with
Ctrl + c
That worked for me

Can't Get Mongrel_Service Gem to Start Mongrel as a Windows Service

I’m more or less a newb to Ruby on Rails, but I’ve been tasked with debuging a Rails app that guy that’s no longer around wrote. The app is running on a manchine using:
• Windows XP Professional
• Apache 2.2
• Rails 2.3.8
• mongrel (1.1.5 x86-mingw32)
• mongrel_service (0.3.4 i386-mswin32)
I copied the app from the server and did some debugging on it on my personal machine. I just setup a Git repository on my personal machine and cloned it back over to the server. Everything seems to be working great except mongrel_service doesn’t work anymore. Each time I try to start the service from Windows “Services” tool I get this error:
The MYAPP_Mongrel_As_Service service on Local Computer started and then stopped. Some services stop automatically if they have no work to do, for example, the Performance Logs and Alerts service
I tried removing the service with:
C:\MyApp>mongrel_rails service::remove --name MYAPP_Mongrel_As_Service
Stopping MYAPP_Mongrel_As_Service if running...
MYAPP_Mongrel_As_Service service removed
and reinstalling it with:
C:\MyApp>mongrel_rails service::install --name MYAPP_Mongrel_As_Service -c "C:\MyApp" --port 3001 --env
ironment production --address localhost --log "log\mongrel_as_service.log" --pid "tmp\pids\mongrel_a
s_service.pid"
MYAPP_Mongrel_As_Service service created.
But no matter how many times I try, or what options I use, I can’t get the service to run. What’s weird is that I can get mongrel to startup by itself just fine.
C:\MyApp>mongrel_rails start -c c:\MyApp --port 3001 --environment production --address localhost --
g "c:\MyApp\log\mongrel_as_service.log" --pid "C:\MyApp\tmp\pids\mongrel_as_service.pid"
** Starting Mongrel listening at localhost:3001
** Starting Rails with production environment...
** Rails loaded.
** Loading any Rails specific GemPlugins
** Signals ready. INT => stop (no restart).
** Mongrel 1.1.5 available at localhost:3001
** Use CTRL-C to stop.
It just won’t work when I try to start it as a service. I've done a lot of googling on the subject, but I can't find anything to fix the problem. It's odd that it was working before but now it doesn't. There must be something wrong with my service::install line because I can't get the original unedited Rails app to work with mongrel_as_service either.
I figured it out. It turns out that the log file for mongrel_service didn't exist on my file. To fix the problem, I just made a blank text file and renamed it to the name of my log file. It worked like a charm. It's odd that mongrel_service doesn't make it's own log file if it can't detected it, but oh well.

How to run thin in the vps after the terminal window is closed

Hey guys
After several weeks of local testing, I'm now setting up a VPS, and try to run rails on it. At this point, I can open up a Terminal session and ssh to the VPS, run the thin start, then I the server is running ok, But as soon as I closed the terminal the thin is down.
How can I make thin server running in the VPS all the time?
another question how to change from test mode to production mode in rails.
Thanks
Demonize thin, run it with -d flag.
thin -d
For the task at hand you will want to use a tool called Screens
Install it:
sudo apt-get install screen
Then to run it you run:
screen -d executable
To put screen to background: Ctrl+D
To recall a screen: screen -r.
You should be all good now.
You don't really want to launch and stop thin by hand. You want it to be a daemon to be started when your system start and to be managed like any other daemons (e.g. nginx, syslog, sshd, etc.). How to do this is very distribution-dependent, but you should definitely have a look at /etc/init.d/ or /etc/rc.d/ and /etc/rc.conf.
To go in production mode within the command line you use thin -e production, but the preferred way should be to specify it in thin's configuration files. You should have (or create) an /etc/thin/ folder, with one .yml file for each application you're deploying.

Resources