-bash: createdb: command not found - django

I'm using a Mac and I already have installed PostgreSQL in my computer using the dmg provided by PostgreSQL (and not by Postgres.app).
I have installed it because I will go to use it with Django, and for to get the correct functionality with the framework, I had to do the next commands:
export PATH=/Library/PostgreSQL/9.5/bin/:"$PATH”
sudo ln -s /Library/PostgreSQL/9.5/lib/libssl.1.0.0.dylib /usr/lib
sudo ln -s /Library/PostgreSQL/9.5/lib/libcrypto.1.0.0.dylib /usr/lib
$ sudo mv /usr/lib/libpq.5.dylib /usr/lib/libpq.5.dylib.old
$ sudo ln -s /Library/PostgreSQL/9.5/lib/libpq.5.dylib /usr/lib
Then I executed the command:
./manage.py migrate
Getting at the terminal a message like this:
And knowing that I needed to create a user "erikb" in PostgreSQL.
I can enter in terminal the command:
sudo su - postgres
To enter to PostgreSQL, but when I wanted to create a DB o a new user, it sent me the next error: -bash: createuser: command not found
Does anyone know which could be the problem?
Regards.

You set the PATH variable in your user account, and then you su'd to a different user. That user does not inherit your environment, including your path.
You need to set the environment for that user, or else use the full path to the createdb command.
export PATH=/Library/PostgreSQL/9.5/bin/:$PATH
createdb erikb

Related

Can't find correct syntax to forward SSH keys

I'm trying to build a custom container with Buildah via a Dockerfile that will run some tasks in Celery, but the tasks need access to a library available in a private repository on our local Gitlab instance. It works if I copy the library from a directory I cloned locally, but it would be best if I could just clone a copy to the container in the Dockerfile. However, I can't get the git clone to work inside the Dockerfile when trying to build it in Buildah. It doesn't seem to be able to read my SSH keys, which are stored on the host at ~/.ssh/id_rsa. I'm trying to follow this from the Buildah man page:
--ssh=default|id[=socket>|<key>[,<key>]
SSH agent socket or keys to expose to the build. The socket path can be left empty to use the
value of default=$SSH_AUTH_SOCK
To later use the ssh agent, use the --mount flag in a RUN instruction within a Containerfile:
RUN --mount=type=secret,id=id mycmd
So in my Dockerfile:
RUN mkdir -p -m 0700 ~/.ssh && ssh-keyscan -t ed25519 gitlab.mycompany.com >> ~/.ssh/known_hosts
RUN --mount=type=ssh git clone git#gitlab.mycompany.com:jdoe/library.git /opt/library
And when I try to build it in Builad:
buildah build --ssh=default -f celery/Dockerfile -t celery
And the error when Buildah gets to the step where it's trying to clone the git repository:
Permission denied, please try again.
Permission denied, please try again.
git#gitlab.mycompany.com: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
error building at STEP "RUN --mount=type=ssh git clone git#gitlab.mycompany.com:jdoe/library.git /opt/library": error while running runtime: exit status 128
Finished
git clones work correctly using my default SSH keys on my host, but whatever I'm doing to access the keys when building the Dockerfile in Buildah isn't working correctly. What do I need to change to get use the SSH keys inside of Buildah?
PS Buildah version, on RHEL8:
$ buildah -v
buildah version 1.26.2 (image-spec 1.0.2-dev, runtime-spec 1.0.2-dev)
EDIT: So I figured out how to get it to work via the --secret flag. Dockerfile:
RUN --mount=type=secret,id=id_rsa GIT_SSH_COMMAND="ssh -i /run/secrets/id_rsa" git clone git#gitlab.mycompany.com:jdoe/library.git /opt/library
Command line:
buildah build --secret id=id_rsa,src=/home/wile_e8/.ssh/id_rsa -f celery/Dockerfile -t celery
This works, although only once. When I try to run this command next in the Dockerfile:
WORKDIR /opt/library
RUN --mount=type=secret,id=id_rsa GIT_SSH_COMMAND="ssh -i /run/secrets/id_rsa" git fetch --all --tags --prune
I get the following error:
###########################################################
# WARNING: UNPROTECTED PRIVATE KEY FILE! #
###########################################################
Permissions 0755 for '/run/secrets/id_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "/run/secrets/id_rsa": bad permissions
Permission denied, please try again.
Permission denied, please try again.
git#gitlab.mycompany.com: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Looks like I'll have to figure out how to set permissions on the secret file. But I still have no idea on how to get the --ssh flag to work correctly, which should be easier than doing all this stuff with the secret file.
EDIT 2: And here is how I managed to run multiple commands that contact the private Gitlab repository - Dockerfile:
ENV GIT_SSH_COMMAND="ssh -i /run/secrets/id_rsa"
RUN --mount=type=secret,id=id_rsa git clone git#gitlab.mycompany.com:jdoe/library.git /opt/library && \
cd /opt/library && \
git fetch --all --tags --prune && \
git checkout tags/1.0.0 -b 1.0.0
Still not as convenient as figuring out the correct syntax for the --ssh flag, but it works.
I eventually figured out how to format this to get the --ssh flag to work. Although I'm now updated to version 1.27.2, so maybe it was a bug fix.
$ buildah -v
buildah version 1.27.2 (image-spec 1.0.2-dev, runtime-spec 1.0.2-dev)
But here is how I formatted the buildah command:
buildah build --ssh id=/home/wile_e8/.ssh/id_rsa -f celery/Dockerfile -t celery
And here is the git fetch line in the Dockerfile:
RUN --mount=type=ssh,id=id git clone git#gitlab.mycompany.com:jdoe/library.git /opt/library && \
cd /opt/library && \
git fetch --all --tags --prune && \
git checkout tags/1.0.0 -b 1.0.0
I don't know why --ssh=default doesn't automatically pull ~/.ssh/id_rsa, but manually specifying that file in this way works.

GCE startup script: can't find $HOME after exporting in startup script

I am trying to run a GCE startup script that downloads all dependencies, clones a repository and runs a python program. Here is the code
#! /usr/bin/bash
apt-get update
apt-get -y install python3.7
apt-get -y install git
export HOME=/home/codingassignment
echo $HOME
cd $HOME
rm -rf sshlogin-counter/
git clone https://rutu2605:************#github.com/rutu2605/sshlogin-counter.git
nohup python3 -u ./sshlogin-counter/alphaclient.py > output.log 2>&1 &
When I run echo$HOME, it displays the path in the log file. However when I cd into it, it says directory not found
May 08 23:15:18 alphaclient google_metadata_script_runner[488]: startup-script: /home/codingassignment
May 08 23:15:18 alphaclient google_metadata_script_runner[488]: startup-script: /tmp/metadata-scripts701519516/startup-script: line 7: cd: /home/codingassignment: No such file or directory
That's because at the time when the script is executed, the /home/codingassignment directory doesn't exist yet. To quote the answer you referred to in the comment:
The startup script is executed as root when the user have been not created yet and no user is logged in
The user home directory for the codingassignment user is created later, when you try to login through SSH for example, if you're using the SSH button in Cloud Console or use the gcloud compute ssh command.
My suggestion:
a) Download the code to some "neutral" directory, like /assignment and set proper permissions for this folder so that the codingassignment user can access it later.
b) Try first creating the user with adduser - this might solve your problem. First create the user, then use su codingassignment to drop root permissions, if you don't need them when executing the script.

Access denied After MySQL Manual Installation on Google Compute Engine

Somehow I wanted to install MySQL manually, so I did as explained in How to Set Up MySQL on Google Compute Engine except that I didn't need to create a VM instance because I already have one.
That is, since my OS is 'Debian GNU/Linux 9 (stretch)', I executed the following two commands to install MySQL:
$ sudo apt-get update
and
$ sudo apt-get -y install mysql-server
There's no errors in this step and I created a root password by the following command:
$ sudo mysql_secure_installation
But when I tried to connect to MySQL, (entering the root password I created)
$ mysql --user=root --password
I've got
ERROR 1698 (28000): Access denied for user 'root'#'localhost'
What would be a problem here and what should I check in order to connect to MySQL?
There is an error on the tutorial. In order to connect to the MySQL you should run:
$ sudo mysql --user=root --password

setting up postgresql/constantly giving me error could not connect to server:

Hello I'm trying to use postgresql, on my digital ocean provided server.
I did $ sudo apt-get install postgresql then $ sudo su postgres then $ createuser -P djangousr but then now I get an error:
createuser: could not connect to database postgres: could not connect
to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
I googled around but just couldn't find a solution. any help would be appreciated
Once you install the server, you have to configure it - it should have prompted to configure it for you. If it didn't, run the following command to reset the installation:
sudo apt-get update
sudo apt-get remove --purge postgresql
sudo apt-get install postgresql postgresql-contrib
Once they finish, then follow this tutorial. To test if everything is working, the following commands should get you to the postgresql shell:
sudo -i -u postgres
psql
Use \q to quit the shell.
I've run into this error, too. Try this command
ln -s /tmp/.s.PGSQL.5432 /var/run/postgresql/.s.PGSQL.5432
This worked out for me... Hope that helps!

Heroku Tool belt installation- No Directory exist

After installing Heroku Toolbelt, in terminal in Ubuntu , After login authentication
I enter
red#red-p7-1039:~$ cd ~/myapp
I get error
-bash: cd: /home/red/myapp: No such file or directory
Other solution tried with no success: As seen in this SOF thread Heroku command not found
-Manually adding the symlink after installing Toolbelt.
sudo ln -s /usr/local/heroku/bin/heroku /usr/bin/heroku
It tells me File already exist.
this isn't an issue with the toolbelt at all. You're trying to enter a directory /home/red/myapp that does not exist.