What text editor is available in Heroku bash shell? [closed] - heroku

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
I'm trying to update httpd.conf in my Cedar-based Heroku app. I got to my Heroku bash with
heroku run bash
and found the conf dir under apache. But when I try to open any editor vi, vim, or emacs, I can't find any of these programs. How do you edit conf files on Heroku?

I recently turned the original gist into a heroku cli plugin.
Just install:
heroku plugins:install https://github.com/naaman/heroku-vim
And use:
heroku vim
The heroku vim command will drop you into a bash shell with vim installed on your $PATH. All you have to do is retrain your fingers to type heroku vim instead of heroku run bash.

If you don't want to mess around with plugins and just want a copy of nano in your one-off dyno, just run
mkdir /app/nano
curl https://github.com/Ehryk/heroku-nano/raw/master/heroku-nano-2.5.1/nano.tar.gz --location --silent | tar xz -C /app/nano
export PATH=$PATH:/app/nano
This will download a copy of nano from this plugin and put it in your PATH.

there's ed if you're a masochist.

It looks like you can download and install vim for one session:
#!/usr/bin/env bash
curl https://s3.amazonaws.com/heroku-jvm-buildpack-vi/vim-7.3.tar.gz --output vim.tar.gz
mkdir vim && tar xzvf vim.tar.gz -C vim
export PATH=$PATH:/app/vim/bin
This idea was found here.

Even if you could edit the files with vi it probably wouldn't solve your problem because the file system is ephemeral. Meaning... If you edit a file via heroku run bash you aren't actually changing the file for other dynos. To change a file for all dynos you need to either change what you push in a Git repo or change the buildpack. More details:
https://devcenter.heroku.com/articles/oneoff-admin-ps#formation-dynos-vs-oneoff-dynos

The plugin provided by Naaman Newbold is no longer working with heroku-16 stack, so I made a new plugin out of this updated gist.
Install:
heroku plugins:install #jasonheecs/heroku-vim
And use:
heroku vim

In the comments on the Brian Takita's answer link, there is the more recent solution to get Vim working on the Heroku console:
https://gist.github.com/dvdbng/7375821b20f189c189ab1bd29392c98e
Just saved me a lot of time! :)

Debugging on Heroku
Prepare the dyno
After installing naaman/heroku-vim you can create a new ephemeral dyno via heroku vim. As pointed out correctly by other posts you won't be able to see your changes when viewing through the browser because changes won't be propagated, but... you can actually view the changes from inside the dyno itself.
I've only experimented with "browsing" via curl, but if you could get lynx on there, or better yet get an ssh tunnel -- could be really great.
Start the server
The web server won't be running when you instantiate heroku-vim so you'll need to do it yourself. In my example I'm running php:
~ $ cat Procfile
web: vendor/bin/heroku-php-apache2
You can start this command yourself!
~ $ vendor/bin/heroku-php-apache2 2>/dev/null &
[2] 845
It's now running in the background!
curl your website
Dynos start up on random ports. Luckily you know which one because it's the $PORT variable!
~ $ curl localhost:$PORT
Hello World!
Editing
Do your vim thing now, but when you save the file and curl again - you won't see the changes. I don't understand where it's cached, but it's cached. You have to kill the server and restart it.
Restarting the server
Find the process id
~ $ ps -f
UID PID PPID C STIME TTY TIME CMD
u6897 3 1 0 05:34 ? 00:00:00 bash
u6897 582 3 0 05:53 ? 00:00:00 bash vendor/bin/heroku-php-apache2
u6897 652 582 0 05:53 ? 00:00:00 bash vendor/bin/heroku-php-apache2
u6897 653 582 0 05:53 ? 00:00:00 bash vendor/bin/heroku-php-apache2
Here 582 is the parent id -- use that.
kill 582
Wait just 1 second, and then start the server again (you'll get a new process id!). Curling via the same command will now give you the updated page.

An urgent alternative to edit a file in Heroku:
place a copy of it on some remote host. I like to use Gist
edit the file on Gist and when finished get the raw URL to it
wget the raw URL on your Heroku bash
copy the fetched file to the path of original file

I wrote a complete article on How to Edit a File on Heroku Dynos using Nano or Vim, but basically:
You can use command line:
curl https://s3.amazonaws.com/heroku-jvm-buildpack-vi/vim-7.3.tar.gz --output vim.tar.gz
mkdir vim && tar xzvf vim.tar.gz -C vim
export PATH=$PATH:/app/vim/bin
You can use Heroku Plugins: heroku-vim
You can use Heroku Buildpacks: heroku-buildpack-vip
Hope it helps!

If you would like to just view the contents of the file then:
cd to the folder where the file is located e.g. $ cd folder
run cat command + the filename e.g. $ cat filename.csv

There are now a number of buildpacks that include vim: https://elements.heroku.com/search/buildpacks?q=vim
You could add one of these to the Heroku app in question, using support buildpack support.

the alternative way if your server run php is to upload PHP File Manager, it single file and you can download it from
http://phpfm.sourceforge.net/

One can change files in a dyno and see the result without pushing to Heroku:
Install heroku-buildpack-vim buildpack:
$ heroku buildpacks:add \
https://github.com/carloluis/heroku-buildpack-vim
Ssh into a dyno:
$ heroku ps:exec
Create and run start.sh:
#!/usr/bin/env bash
set -eu
export DATABASE_URL=...
bin/rails s -p 4000
Forward port 4000 (second console):
$ heroku ps:forward
Open localhost:4000 in your browser.
Stop start.sh, change a file, start again, refresh the browser page.

I prefer Nano editor, you can use following buildpack...
https://github.com/velizarn/heroku-buildpack-nano

Related

Bash script to run firebase functions [duplicate]

This question already has an answer here:
Run two shell commands
(1 answer)
Closed 6 months ago.
I'm a complete noob with bash scripting so maybe a stupid question: I have 3 scripts to auto run a react web app along with firebase cloud functions, the project structure is something like this:
-general:
|_start.sh
|_start-frontend.sh
|_start-backend.sh
-backend
|_functions
-frontend
|_my_app
please note that general is an npm project with a package.json file:
{
"name":"my_app",
"version":"0.1.0",
"workspaces":[
"backend/functions",
"frontend/my_app"
],
"author":"Giulio Serra",
"license":"ISC",
"scripts": {
"start": "sh ./start.sh"
}
}
so when I run npm start start.sh is executed:
#!/bin/bash
open -a Terminal "`sh start-backend.sh`"
open -a Terminal "`sh start-frontend.sh`"
here are the content of start-frontend:
#!/bin/bash
cd ../frontend/my_app
npm start
and start-backend:
#!/bin/bash
cd ../backend/functions
kill $( lsof -i:8085,9000 -t )
firebase emulators:start --import /Users/giulioserra/Documents/Applicazioni/my_app/backend/dev_res
I just want to open 2 terminals: one with react and another with the emulators suite with the functions, but all I managed to do is to open one terminal with just the emulator suite (basically start-frontend.sh gets ignored) without any logs.
if I switch the instructions on the file: start-backend it's ignored and start-fronted.sh is executed again without any logs (so I don't have any clues about the port used and compiled warnings).
Any hints on how to fix the scripts such as both start-frontend.sh and start-backend.sh are executed on two different terminal instances with the proper logs?I'm on Mac Monterey btw Thanks.
Turns out that it was simple as:
sh start-backend.sh & sh start-frontend.sh
thanks to triplee for the help.

How to run a tmux session as startup_script in google cloud?

I want to run a python script in a tmux session on startup when launching my google cloud vm. I have searched around stack overflow and found this piece of code.
#! /bin/bash
sudo -H -u MyUser tmux new-session -d -s discord 'python3 MyFile.py'
I placed this in the meta data part of my vm where startup_scripts go but it doesn't launch when i start my vm. However when I run this code in the terminal after my vm has started it does exactly what I want it to do. What am I missing here?
After digging around for I while I found the problem. The command runs in the root directory so, before your piece of code, you have to add:
Add: cd home/username
Before your code.

How to launch a new process in a new terminal in Linux

I'm using Linux Mint 19 Cinnamon. I've an Angular project and I want to do the following things. All these in a separate terminal:
Navigate into project folder and run code . so that I can see the code on Visual studio.
Navigate into project folder and run ng serve to launch my application and keep it running.
Navigate into project folder and run node server.js to start backend server and keep it running.
this is very painful as the project location is-
home/xpert/Documents/social-coder
and it contains two servers:
social-coder/application The angular server that runs on localhost:4200
social-coder/server/server.js The backend server that runs on localhost:3000
Both the servers need to be constantly running for the application to work.
Navigating again and again with a new terminal is what wasting my time. I decided to write a shell script so that I can do all at once with one single click. This is what my .bashrc file contains:
alias first='gnome-terminal | npm start --prefix Documents/social-coder/application'
alias second='node Documents/social-coder/server/server.js'
alias third='code Documents/social-coder'
This is what I've thought. SO, all of the above 3 commands works perfectly If I manually copy-paste them in separate terminals. But again, I have to manually open 3 different terminals and make them run. I'm coming from:
How to write practical shell scripts - Like Geeks
Run command on another(new) terminal window
How to Use GNOME Terminal App
gnome-terminal opens a new terminal but still runs npm start from the same terminal itself.
I admit that I'm a newbie and there are gaps in my knowledge. Please correct me.
For now I've created a command using pipe. It is working but I'm not sure whether this is the preferred way or not:
gnome-terminal -- /bin/bash -c 'npm start --prefix Documents/social-coder/application' | gnome-terminal -- /bin/bash -c 'node Documents/social-coder/server/server.js' | gnome-terminal -- /bin/bash -c 'code Documents/social-coder'
Please feel free to edit this answer.

Cannot clone an aegir site

I am getting this error while cloning the site on aegir
Unknown option: --profile. See drush help provision-backup for available >options. To suppress this error, add the option --strict=0. [2.39 sec, 21.19 MB]
I am using aegir3 on ubuntu 14.04.4. Can anyone please help me solve this. I have searched on web but there is no solution regarding this issue. This issue also occurs while migrating.
you might find more Aegir users at the new community support forum
http://ask.aegir.support/
I had a similar issue and found a solution there
I found that debugging Aegir issues was a lot easier if you executed the Drush commands directly.
You can find the command by looking through the Log Messages keeping an eye out for entries like
Backend invoke: /usr/bin/php -d magic_quotes_gpc=Off -d magic_quotes_runti... (Expand)
Below entries like the above you will find the command that was executed, expand that by clicking the (Expand) and copy the command (I found sometimes the expand did not work, in cases like this I just use chrome tools to look at the source and copy it)
/usr/bin/php -d magic_quotes_gpc=Off -d magic_quotes_runtime=Off -d magic_quotes_sybase=Off /var/aegir/.composer/vendor/drush/drush/drush.php --php=/usr/bin/php --php-options=' -d magic_quotes_gpc=Off -d magic_quotes_runtime=Off -d magic_quotes_sybase=Off' --backend=2 --yes #centosintranet provision-install-backend --client_email='this.email#is.invalid' 2>&1
All you need to do now is run this as the Aegir user via bash. If you use the apt-get package to install Aegir you should be able to open a terminal and enter
sudo su - aegir -s /bin/bash
You will be prompted for your password, after entering it you will have a bash shell as the Aegir user. Paste in the above drush command and press enter.
Watch it execute, I found it easier to work out what was going on by removing the --backend=2 option. If you still can't see what the issue is try adding -vvv or --debug to the drush command.
Using this method I have solves all issues I have run into thus far when Aegir falls over.

Mac doesn't boot after running this code [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I know this is kinda off-topic, but since I've found the code I'm talking about here on SO I hope that someone can help me.
I was dealing with a POSTGRES error and read here: Can not connect to local PostgreSQL an answer, the one from vvdpzz that lead me to run that code in my terminal.
After that, my mac stopped working and since then it doens't reboot, it comes till the apple logo that keeps flashing and switching with a folder with a question mark.
I've checked the code that curl execute and it's the following:
#!/bin/sh
BREW_POSTGRES_DIR=`brew info postgres | awk '{print $1"/bin"}' | grep "/postgresql/"`
LION_POSTGRES_DIR=`which postgres | xargs dirname`
LION_PSQL_DIR=`which psql | xargs dirname`
sudo mkdir -p $LION_POSTGRES_DIR/archive
sudo mkdir -p $LION_PSQL_DIR/archive
for i in `ls $BREW_POSTGRES_DIR`
do
if [ -f $LION_POSTGRES_DIR/$i ]
then
sudo mv $LION_POSTGRES_DIR/$i $LION_POSTGRES_DIR/archive/$i
sudo ln -s $BREW_POSTGRES_DIR/$i $LION_POSTGRES_DIR/$i
fi
if [ -f $LION_PSQL_DIR/$i ]
then
sudo mv $LION_PSQL_DIR/$i $LION_PSQL_DIR/archive/$i
sudo ln -s $BREW_POSTGRES_DIR/$i $LION_PSQL_DIR/$i
fi
done
What happened? I'm not an expert. How can I solve this. I've tried to start in secure mode by pressing the shift key while booting but it doesn't work.
This is a good example of why you shouldn't run scripts without understanding what they do. My guess is that one or both of LION_PSQL_DIR and LION_POSTGRES_DIR came out as empty and the script ended up moving things around in your root directory. You should be able to recover your system by following these steps:
Boot your OS X installation disc by putting it in the drive and holding the C key while booting.
From the Utilities menu, choose Terminal
Run the command cd /Volumes
Run the command ls which should show an entry corresponding to the name of your Mac's hard drive
Run the command cd "<name of your hard drive>"
Run the command ls. If the problem is that things got moved from the root of your drive, there will be an archive entry, if there isn't then stop since this will not fix your problem.
Run the command cd archive to enter the archive directory
Run the command mv * .. to move everything in the archive directory back to the root of your harddrive
Close the terminal
Run Disk Utility from the Utilities menu and use repair permissions on your drive.
Reboot your computer and hopefully it will work right now
Never run random scripts like that again.
The 10th step might not be strictly necessary. I haven't tried to do these steps myself, but they should be pretty close to correct. If you get any errors during them stop and put a comment and I will try and figure out how to proceed.

Resources