Bash shell on a Heroku Dyno

2013-02-27 / All Blog posts

Up to now most of my work with Heroku has been via the heroku command line client, and pushing builds to app instances to have them compiled and run. Recently I've been messing around with the remote bash shell of my Heroku apps. To enter a remote shell, just type the following from the root directory of a git project that declares your Heroku app as a remote repository. This command uses the heroku client provided by the Heroku toolbelt:

heroku run bash

Upon login, you are placed into the root directory of your deployed app. Unfortunately, you do not have access to the table of mounted file systems and you cannot run sudo.

~ $ pwd
/app
~ $ ls -alF
total 64
drwx------ 10 u37570 37570 4096 Dec  1 01:07 ./
drwxr-xr-x 15 root   root  4096 Oct 31  2011 ../
-rwx------  1 u37570 37570  183 Dec  1 01:05 .gitignore*
drwx------  3 u37570 37570 4096 Dec  1 01:05 .ivy2/
drwxrwxr-x  6 u37570 37570 4096 Dec  1 01:05 .jdk/
drwx------  4 u37570 37570 4096 Dec  1 01:08 .sbt_home/
-rw-------  1 u37570 37570   98 Dec  1 01:05 Procfile
-rw-------  1 u37570 37570 3833 Dec  1 01:05 README.md
drwx------  5 u37570 37570 4096 Dec  1 01:05 app/
drwx------  2 u37570 37570 4096 Dec  1 01:05 conf/
drwx------  5 u37570 37570 4096 Dec  1 01:06 project/
drwx------  5 u37570 37570 4096 Dec  1 01:05 public/
-rwx------  1 u37570 37570   27 Dec  1 01:05 system.properties*
drwx------  6 u37570 37570 4096 Dec  1 01:08 target/

Discover total used file space (my slug uses 1.7GB):

~ $ du -sh /
du: cannot read directory `/proc/tty/driver': Permission denied
du: cannot read directory `/proc/1/task/1/fd': Permission denied
du: cannot read directory `/proc/1/task/1/fdinfo': Permission denied
du: cannot read directory `/proc/1/fd': Permission denied
du: cannot read directory `/proc/1/fdinfo': Permission denied
du: cannot access `/proc/11/task/11/fd/4': No such file or directory
du: cannot access `/proc/11/task/11/fdinfo/4': No such file or directory
du: cannot access `/proc/11/fd/4': No such file or directory
du: cannot access `/proc/11/fdinfo/4': No such file or directory
du: cannot read directory `/lost+found': Permission denied
du: cannot read directory `/etc/ssl/private': Permission denied
1.7G /

All your environment variables are available:

set # Miles of output

ifconfig is not available, but the IP address of your dyno can be discovered this way:

~ $ tail -n 1 /etc/hosts
10.92.81.76 e3d315e6-4392-4f3a-b7ae-75438c469697

You can run sbt, but this is a bad idea, because the Ivy cache is held outside the dyno, and there is no way for you to clean it without using some voodoo.

~ $ sbt update
[info] Loading global plugins from /app/.sbt_home/.sbt/plugins
[info] Loading project definition from /app/project
[info] Set current project to blahblah (in build file:/app/)
[info] Updating {file:/app/}blahblah...
... miles of output ...
[info] Done updating.
[success] Total time: 6 s, completed Feb 28, 2013 4:40:21 AM

comments powered by Disqus