Heroku Cedar Stack and command heroku run console - heroku

In my old Ruby 1.9.2 Sinatra apps running on Bamboo stack, heroku console provided a shell that not only initialized Active Record but also logged to a history file in my .heroku directory.
After moving to Heroku Cedar stack and using Ruby 1.9.3, I found heroku run console did not load any of my Active Record models. I fixed that by writing a small ruby script to initialize Active Record and load my models.
I execute this using the awkward heroku run 'bundle exec irb -r ./console'
This IRB console fires up fine and gives me access to my model data, but no history is logged.
1) Why is heroku run console so neutered?
2) How can I get my console sessions to log to history?
Please?
Thanks

Add the following line to your Procfile:
console: bundle exec irb -r ./console
Keeping the history is not easily possible, as it will spin up a dyno for every new invocation (cedar stack doesn't keep the history for Rails console, either). You could try using rlwrap to keep your history on the local machine.

From the docs:
You can use heroku console as a stand-in for Rails’s script runner, to
run one-time commands directly from the command line
and
Without an argument, heroku console launches an interactive console
similar to irb or the Rails script/console command
run console is aimed at running the Rails console, or irb.

Related

How to run auto restart in heroku for ruby scripts

In my Dev box on Nitrous, I am able to run God -c scripts.god -D to restart the two .rb files if they die.
I just run that and the processes for the most part stay alive.
But I cannot do the same in heroku. It seems when I run the god command the .god file does not open and generates an error in heroku.
Question:
How can I run God to restart failed processes in heroku as I do on my development Nitrous environment?
Or is there a recommended alternative way to watch heroku processes and restart them automatically when they fail?
On Heroku you shouldn't need to use a process supervisor like god. If all you need is to ensure your process is restarted if it crashes, Heroku can manage that fine.
It should be as simple as adding two entries in your procfile as workers. https://devcenter.heroku.com/articles/background-jobs-queueing
worker: bundle exec sidekiq
clock: bundle exec clockwork lib/clock.rb
slack_listener: bundle exec ruby lib/slack_bot.rb
You could possibly have issues, if your processing are crashing quite often. Dyno Crash Restart Policy
Your processes should start automatically when you access your website.
However, Heroku does provide commands to manage your processes, check out https://devcenter.heroku.com/articles/dynos for the complete list. E.g., to restart all processes, use the toolbelt command:
heroku ps:restart --app yourappname

How to visualize my first post with octopress?

I installed octopress (git,RVM) as documented on octopress.org
I created one post and executed the commands:
rake generate
rake preview
This last command is never finished !?
Any explanation ?
Ruby version 2.0.0
The command
rake watch
also loops
rake preview is a command which launches your site running locally on port 4000. Therefore if you execute that command and browse to localhost:4000 you should see your site. The command will appear to be running constantly (until you ctrl-c out) as it is running a server.
This is covered under the blogging basics - http://octopress.org/docs/blogging/
rake watch will also run continually as all it is designed to do is monitor for changes in your source and sass then if any are detected will automatically run a generate task.

System commands dont work when running over passenger

I have a sinatra app with a page that shows some information about the application. Some of which is generated by running commands on page load. Everything works fine on my MacBook when running in unicorn and everything works fine on the production server when running in unicorn but swap to Apache/Passenger and suddenly the commands start returning nil.
For example to get a list of committers I use:
comitters = `cd /path/to/app && git shortlog -s -n`
This works perfectly until run in the apache/passenger setup.
Is there some option within passenger that disables system commands?
The problem lies in your $PATH environment variable, which the system uses to look for commands. You run Unicorn from the shell don't you? So Unicorn inherit $PATH from your shell. But app processes started from Phusion Passenger are started from Apache/Nginx, which in turn are usually started from some system init service, which have completely different environment variables than your shell. Read http://blog.phusion.nl/2008/12/16/passing-environment-variables-to-ruby-from-phusion-passenger/ for a solution.

heroku cedar console

I've been trying to get a heroku console session going on cedar and am having no joy.
The old way was:
heroku console
I understand the new way involves 2 steps:
heroku run bash
then
$ rails console
but at the heroku run bash stage i keep geting:
heroku run bash
Running `bash` attached to terminal... up, run.1
!
! Timeout awaiting process
so i checked there isn't a port blocking issue and
telnet rendezvous.heroku.com 5000
gives
Trying 50.19.103.36...
Connected to ec2-50-19-103-36.compute-1.amazonaws.com.
Escape character is '^]'.
which is as expected i think
what am i doing wrong and what do i need to do to get this console up and running?
Thanks!
PS I have tried - heroku run console - also, and that times out too.
In cedar every command that needs to be attached to terminal uses run.
ex:
heroku run console
heroku run rake db:migrate
When its not necessary to be attached don't use the run:
ex: heroku logs
The new way is heroku run console
Ok - it was obvious after a few hours of sleep. Simply had to update the heroku gem that had got corrupted somehow on my mac. If you have something like this problem, then do that first...

Why can't I start a Heroku console on the Cedar stack?

Trying to debug a new Heroku deployment - seems to be missing a db table. To do this, I'm running heroku run console but I get back :-
Running console attached to terminal... up, run.7
sh: console: not found
under both my Linux and Windows environments
What have I missed to get this working?
[Very late update : this is for a Java Heroku app, not a RoR one, so anything related to rails is a little lost on me]
on Celadon Cedar Stack it is changed to:
$ heroku run bash
$ heroku run bash
then
…#…:/app$ script/rails console
It worked for me. Though the second step is specific to Ruby on Rails – I don’t know the equivalent commands for other platforms and frameworks.
To run rails console, it's just:
heroku run rails console

Resources