Heroku can not ssh into a free dyno - heroku

What I am trying to do:
What I have done to resolve the issue:
1.
2. From this: yes, I have /app/.profile.d/heroku-exec.sh.
3.
4. I found also this. And saw that rm /bin/sh && ln -s /bin/bash /bin/sh may help. But it is for docker and I do not know where to insert it if I do not use docker. I tried to create Procfile with the following content: web: rm /bin/sh && ln -s /bin/bash /bin/sh (do not judge me, I just tried). But in this case a dyno only crashed.
I was a little confused when I did not find relevant information about this error. Heroku does not provide docs for this error. As a variant I guess that Establishing credentials... error could mean that I do not pass any authentication. May be. But which one? I can heroku run bash which means that I pass the authentication. Maybe exec requires ssh keys?
Any suggestions?

Related

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.

LD_PRELOAD not working on Heroku + jemalloc + quotaguard

TL;DR: update your bin/qgtunnel.
I've recently noticed an increase in my web dyno's memory usage. After digging a bit, I could see that the LD_PRELOAD variable that should be set with heroku-buildpack-jemalloc was not set correctly. I used a tiny script (bin/show_preload) that helped me debug that and trace which program was overriding LD_PRELOAD.
#!/usr/bin/env bash
echo "buildpack=foo preload='$LD_PRELOAD' at=start-app cmd='$#'"
$#
I introduced that in our Procfile:
web: bin/show_preload bin/qgtunnel bin/show_preload bin/start-nginx bin/show_preload bin/start-pgbouncer bin/show_preload bundle exec puma -C config/puma.rb
And when lauching on heroku I can see that bin/qgtunnel overrides our LD_PRELOAD configuration.
I created a tiny helper for the time being which makes sure I keep original value as well as what is added by bin/qgtunnel:
#!/usr/bin/env bash
after_qgtunnel_script=$(mktemp)
echo <<-BASH > $after_qgtunnel_script
# Retrieve previous LD_PRELOAD value
export LD_PRELOAD="\$LD_PRELOAD $LD_PRELOAD"
# Clean after usage
rm $after_qgtunnel_script
# Start following commands
$#
BASH
chmod +x $after_qgtunnel_script
bin/qgtunnel $after_qgtunnel_script $#
If you ever need this script use it in place of bin/qgtunnel
After reaching out to Quotaguard, they patched the qgtunnel binary and there is no error anymore:
curl https://quotaguard.s3.amazonaws.com/qgtunnel-2.4.1.tar.gz | tar xz
git add bin/qgtunnel vendor/nss_wrapper/libnss_wrapper.so
git commit -m "Update qgtunnel to fix LD_PRELOAD"
NOTE: new versions may occur since that one, see the related documentation

udev rule not working correctly, probably escaping issue

I try to run an udev rule once a mount is ready on a Vagrant box:
SUBSYSTEM=="bdi",ACTION=="add",RUN+="/usr/bin/screen -m -d bash -c 'sleep 5; cd /vagrant/; sudo -E su -c "pm2 start daemon.json" vagrant;'"
But the command isn't running properly, since the pm2 doesn't start.
When I execute /usr/bin/screen -m -d bash -c 'sleep 5; cd /vagrant/; sudo -E su -c "pm2 start daemon.json" vagrant;' manually it does work.
Any ideas?
The nested quotes are surely part of the problem, but the bigger problem is written in the udev manual:
This can only be used for very short-running foreground tasks. Running an event process for a long period of time may block all further events for this or a dependent device. Starting daemons or other long-running processes is not appropriate for udev; the forked processes, detached or not, will be unconditionally killed after the event handling has finished.
So your approach has to be changed. However, let’s suppose the command pm2 start daemon.json is appropriately short-running: your question is interesting anyway, because similar quote-nesting problems arise often. So please consider the rest of this answer as an example for the general case.
Instead of going mad with the correct escaping sequences, you can just write
RUN+="/usr/bin/screen -m -d bash -c 'sleep 5; cd /vagrant/; sudo -E -u vagrant pm2 start daemon.json"
An even simpler solution might be
RUN+="/usr/bin/screen -m -d /usr/local/bin/start_vagrant_daemon"
where /usr/local/bin/start_vagrant_daemon is executable and has the following content
#!/bin/bash
sleep 5
cd /vagrant/
sudo -E -u vagrant pm2 start daemon.json
Both solutions require setting up the correct sudo authorizations by editing /etc/sudoers or (better) writing them in a new file /etc/sudoers.d/vagrant_daemon after enabling includedir /etc/sudoers.d in /etc/sudoers.

Stop postgreSQL service on Mac via terminal

Running postgreSQL 9.4.5_2 currently
I have tried
pg_ctl stop -W -t 1 -s -D /usr/local/var/postgres -m f
Normally no news is good news but after I will run
pg_ctl status -D /usr/local/var/postgres
and get pg_ctl: server is running (PID: 536)
I have also tried
pg_ctl restart -w -D /usr/local/var/postgres -c -m i
Response message is:
waiting for server to shut down.......................... failed
pg_ctl: server does not shut down
I've also checked my /Library/LaunchDaemons/ to see why the service is starting at login but no luck so far. Anyone have any ideas on where I should check next? Force quit in the activity monitor also isn't helping me any.
Sadly none of the previous answers help me, it worked for me with:
brew services stop postgresql
Cheers
I tried various options; finally, the below command worked.
sudo -u postgres ./pg_ctl -D /your/data/directory/path stop
example
sudo -u postgres ./pg_ctl -D /Library/PostgreSQL/11/data stop
As per the comments, the recommended command is without the ./ when calling pg_ctl:
sudo -u postgres pg_ctl -D /Library/PostgreSQL/11/data stop
Tried sudo and su but no such luck.
Just found this gui
https://github.com/MaccaTech/postgresql-mac-preferences
If anyone can help with the terminal commands that would be very much appreciated, but till then the gui will get the job done.
Had the same issue, I had installed postgres locally and wanted to wrap in a docker container instead.
I solved it pretty radically by 1) uninstalling postgres 2) kill the leftover process on postgres port. If you don't un-install the process restarts and grabs the port again - look at your Brewfile form brew bundle dump to check for a restart_service: true flag.
I reasoned that, as I am using containers, I should not need the local one anyway, but !! attention this will remove postgres from your system.
brew uninstall postgres
...
lsof -i :5432 # this to find the PID for the process
kill - 9 <the PID you found at previous command>
Note: if you still want to used psql you can brew install libpq, and add psql to your PATH (the command output shows you what to add to your .zshrc, or similar)
you can stop the server using this command
{pg_ctl -D /usr/local/var/postgres stop -s -m fast}
Adding onto the solutions already stated :
if you decide to use the pg_ctl command, ensure that you are executing the command as a user with the permissions to access the databases/database server.
this means :
the current logged in user on your terminal should have those permissions
or
first run :
$ sudo su <name_of_database_user>
pg_ctl -D /Library/PostgreSQL/<version_here>/data/ stop
the same goes for the start command.
credit : https://gist.github.com/kingbin/9435292
(essentially hosted a file with the commands on github, saved me some time :^) )
I had a stray docker container running Postgres that I had forgotten about.

Capistrano :shell example

I'm currently using Capistrano to deploy my web application which works like a charm.
In my new project I must execute a command from sudo /bin/bash shell.
Is it possible for Capistrano to login to the machine as user X, run sudo /bin/bash,
enter the password and then execute a command in the sudo shell? If yes, could you
please provived me with an example.
With regards
jakob
Is there a specific reason you need to be in a root shell rather than executing the command with sudo? If executing a command with sudo, you can simply sudo 'command' instead of run 'command'.
I did a little experimentation to try to get a root shell with capistrano without logging into the server directly as root, and wasn't able to make much progress.
If running with sudo won't work, please update your question to let us know why and maybe we can help you find a workaround for it.
Update:
After playing around a little more, I found that you can execute an individual command (or string of commands) in a root shell by doing something like sudo '/bin/bash -c "whoami"'. It's getting an interactive root shell that's tricky.

Resources