Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access to heroku toolbelt commands in a scheduled heroku dyno?

Tags:

heroku

I want to call heroku postgres backup/restore commands within a scheduled heroku task, but the heroku toolbelt isn't available from bash prompt, so I can't call heroku commands:

$ heroku run bash --app myapp
Running `bash` attached to terminal... up, run.4805
~ $ heroku --version
bash: heroku: command not found

How can I get heroku commands available in my scheduled bash script? I don't know anything about Ruby or Ruby Gems.

like image 762
Heather Piwowar Avatar asked Nov 26 '14 15:11

Heather Piwowar


People also ask

How do I access my heroku command line?

Get Started with the Heroku CLIAfter you install the CLI, run the heroku login command. Enter any key to go to your web browser to complete login. The CLI then logs you in automatically. If you'd prefer to stay in the CLI to enter your credentials, run heroku login -i .

What is heroku toolbelt?

The Heroku Toolbelt is a package of the Heroku CLI, Foreman, and Git — all the tools you need to get started using Heroku at the command line. The Toolbelt is available as a native installer for OS X, Windows, and Debian/Ubuntu Linux. The Toolbelt has been available since last fall as part of our polyglot platform.

How do I schedule a dyno in heroku?

Scheduling jobsOn the Scheduler Dashboard, click “Add Job…”, enter a task, select a frequency, dyno size, and next run time. Note that the next run time for daily jobs is in UTC. If you want to schedule the job at a certain local time, add the proper UTC offset.

How does heroku automatically restart dynos?

Automatic dyno restartscreate a new release by deploying new code. change your config vars. change your add-ons. run heroku restart.


1 Answers

None of the other solutions worked for me since Heroku locks the filesystem after the buildpacks finish running.

There's a third-party buildpack that installs the CLI for you. First you set your auth key as an ENV variable on your app:

heroku config:set HEROKU_API_KEY=`heroku auth:token` -a myapp

Then add the buildpack:

heroku buildpacks:add https://github.com/heroku/heroku-buildpack-cli -a myapp

Redeploy your app and it should be able to access your apps via the CLI. If you have https://devcenter.heroku.com/articles/dyno-metadata enabled, you can even access your current app's name with $HEROKU_APP_NAME.

like image 138
DylanReile Avatar answered Oct 18 '22 10:10

DylanReile