Enable Postgresql in Cygwin - cygwin

I installed Cygwin with Perl and Postgresql packages enabled.
Then typed:
/usr/bin/cygserver-config (This will install the service)
Then type:
net start cygserver(This starts the service)
Next i need to enable Postgresql in Cygwin, so i tried the commands mentioned below:
cygrunsrv -S cygserver
initdb -D /usr/share/postgresql/data
pg_ctl start -D /usr/share/postgresql/data -l /var/log/postgresql.log
createdb
psql
I get an error:
$ initdb -D /usr/share/postgresql/data
-bash: initdb: command not found
$ pg_ctl start -D /usr/share/postgresql/data -l /var/log/postgresql.log
-bash: pg_ctl: command not found
Can someone please tell me how to get it right.

The Postgresql initdb and pg_ctl executables are located under /usr/sbin.
I am guessing that /usr/sbin is not on your PATH setting. Adding it should do the trick.
I use a start/stop script which I keep under $HOME/bin called pg. Here's the gist.

Related

Error while trying to install Kops on Ubuntu 20 EC2 Instance

I went through the steps listed here: https://kubernetes.io/docs/setup/production-environment/tools/kops/
After moving the kops file to /usr/local/bin/ and renaming to kops, I tried to confirm if it was in fact installed and executable by trying 'kops --help' and 'kops --version'/'kops version' and neither command worked. Any idea what the issue might be?
Edit: Here's what I did step by step
curl -LO https://github.com/kubernetes/kops/releases/download/$(curl -s https://api.github.com/repos/kubernetes/kops/releases/latest | grep tag_name | cut -d '"' -f 4)/kops-darwin-amd64
sudo chmod +x kops-darwin-amd64
sudo mv kops-darwin-amd64 /usr/local/bin/kops
It's a t2.micro Ubuntu 20.04 EC2 Instance.
Tried to confirm if kops was properly installed and executable by entering 'kops --help' and 'kops --version' and also 'kops version' but they all return this error:
-bash: /usr/local/bin/kops: cannot execute binary file: Exec format error
I think its because you are using kops-darwin-amd64. This is for mac. I think you should be using kops-linux-amd64 instead for linux.

Running a script to connect through ssh then run npm install pm2 results in: 'npm: command not found'

I'm running this command from my local machine:
ssh -tt -i "pem.pem" ec2-user#ec2-IPADDRESS.compute-1.amazonaws.com "sudo su -c 'cd /dir/;npm install pm2'"
It connects, operates as a super users, cds to dir and attempts to run the command but returns that npm is not a command recognized by the system.
However, when I connect "manually" i.e.
ssh -i "pem.pem" ec2-user#ec2-IPADDRESS.compute-1.amazonaws.com
sudo su
cd /dir
npm install pm2
it works.
npm is installed under root and the system can see it.
ssh -tt -i "pem.pem" ec2-user#ec2-IPADDRESS.compute-1.amazonaws.com "sudo su -c 'cd /dir/;whoami'"
and
ssh -i "pem.pem" ec2-user#ec2-IPADDRESS.compute-1.amazonaws.com
sudo su
cd /dir
whoami
both return "root"
Why can't the npm command be found when running on top of an ssh?
When you login, you create an interactive shell, which typically will read a couple of files, including /etc/profile, $HOME/.profile, and $HOME/.bashrc in the case of bash.
Any of these files can add extra elements (paths) to the PATH variable, which affects which commands can be found.
When you run the command line directly, no such initialisation takes place, and the value of $PATH may be limited to just /bin:/usr/bin.
Next there is sudo, which may or may not import the value of PATH when looking for commands.
Solution
Best you can do is find out where npm is installed, and use its full PATH.

sudo: psql: command not found: can't fix it

When I run
sudo -u postgres psql
I get the
sudo: psql: command not found
error. I can't get it to work.
# locate psql
/etc/alternatives/psql.1.gz
/usr/bin/psql
/usr/lib/postgresql/9.5/bin/psql
/usr/lib/x86_64-linux-gnu/odbc/libodbcpsqlS.so
/var/lib/dpkg/alternatives/psql.1.gz
/var/lib/postgresql/.psql_history
and
# ln -s /usr/lib/postgresql/9.5/bin/psql /usr/bin/psql
ln: failed to create symbolic link '/usr/bin/psql': File exists
Didn't work. Postgresql is running and doing fine, though.
Set up postgres' PATH variable in .bash_profile to contain /usr/lib/postgresql/9.5/bin.
copy the psql binary from the postgreql bin folder to /usr/bin
sudo cp -v /usr/lib/postgresql/9.5/bin/psql /usr/bin/

eval $(docker-machine env myvm1) does not switch to shell to talk to myvm1

Folks,
I'm following the Docker tutorial here: https://docs.docker.com/get-started/part4/#configure-a-docker-machine-shell-to-the-swarm-manager and coming up against resistance when running this particular command:
eval $(docker-machine env myvm1)
I'm actually running (as above but with addition of sudo).
eval $(sudo docker-machine env myvm1)
I get no output from the command line to tell me anything has been done and when I run:
sudo docker-machine ls
I see that myvm1 does not have an active state as expected. I do know that this step isn't necessary but I'd like to understand why the command is not working and try to fix it.
I am running docker 17.09.0-ce
On Ubuntu 16.04 LTS
zsh shell (have tried switching to bash)
This is just on my local machine by the way, not a server.
Any help would be much appreciated.
There's less to go wrong if you run the eval on the far side of sudo:
sudo sh -c 'eval "$(docker-machine env myvm1)"; docker-machine ls'
Otherwise, the environment variables set by evaling the output of docker-machine env aren't necessarily (barring some very specific /etc/sudoers configuration) propagated through to the future docker-machine invocation.
If you wanted to automate this with a shell function, that can be done:
# docker-env sudo; usage: desudo vm-name command-to-run
desudo() {
local cmd1 cmd2
printf -v cmd1 'eval "$(docker-machine env %q)"' "$1"; shift
printf -v cmd2 '%q ' "$#"
sudo bash -c "${cmd1} && exec ${cmd2}"
}
...used as:
desudo vm1 docker-machine ls
You should run eval $(docker-machine env myvm1).
In fact, you don't have to add sudo.
But you may doesn't have permission to run docker without sudo, here is how to solve this issue on Linux.
Following the steps in this article "Post-installation steps for Linux"
Create the docker group. sudo groupadd docker
Add your user to the docker group. sudo usermod -aG docker $USER
Log out and log back in so that your group membership is re-evaluated.
Verify that you can run docker commands without sudo.docker run hello-world.
If you see the following error:
WARNING: Error loading config file: /home/user/.docker/config.json -
stat /home/user/.docker/config.json: permission denied
Fix it with:
$ sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
$ sudo chmod g+rwx "/home/$USER/.docker" -R
I too was having the exact same problem as posted and have spent the better part of the morning googling for an answer. I went back through the documentation and realised that I completely omitted the post-installation steps for Linux.
https://docs.docker.com/install/linux/linux-postinstall/
I followed the instructions laid out in the section labelled Manage Docker as a non-root user and eval $(sudo docker-machine env myvm1) and the subsequent docker-machine ls worked as expected. In addition... it eliminates the need to prefix all your docker commands withsudo.
I should have RTFM I guess?
I'm actually running (as above but with addition of sudo).
eval $(sudo docker-machine env myvm1)
I get no output from the command line to tell me anything has been done and when I run:
sudo docker-machine ls
I see that myvm1 does not have an active state as expected.
run this command it will work
sudo sh -c 'eval "$(docker-machine env myvm1)"; docker-machine ls'

Installation of Cron in cygwin

When I run the following command in cygwin,
$ cygrunsrv -I cron -p C:\cygwin64\bin --args -n
I get the following error
cygrunsrv: Given path doesn't point to a valid executable
Why am I getting this error?
You only gave a folder and not a path to the executable. Besides this I wouldn't recommend to use windows paths in cygwin, this can cause errors. You should write /cygdrive/c/cygwin64/bin/something instead of C:\cygwin64\bin\something.exe
Perhaps you are looking for an
installation guide, and you would like to do something like this:
Install cron as a windows service, using cygrunsrv:
cygrunsrv -I cron -p /usr/sbin/cron -a -D
net start cron

Resources