Python Fabric is hanging - python

I've got an instance running on AWS EC2. Doing this:
ssh -i keyname.pem user#box.com
Works!
Using Fabric to deploy my stuff now:
fab -i keyname.pem -k deploy:host=user#box.com
Same key, same user/host, but it hangs miserably! No logging, just hangs.
Does anyone know how different are ssh settings that Fabric is trying to use from those in the system? I thought it is just wrap around SSH shell commands (I'm running all that from Cygwin if it matters). Completely stuck with this.
I've googled out a few threads where people complain about that, but all I found is recommendations to update Fabric. I have the newest one from cheese shop (Fabric v1.10.1, Paramiko v1.15.2), still this strange behavior to hang without saying anything.

Have you try to set env with all the information?
`from fabric.api import env
env.env_name = 'user'
env.key_filename = 'keyname.pem'
env.hosts = ['box.com']`

I hit this same error before. Try ssh-ing into the server with ssh from terminal before using fabric. Sometimes is needs to be added to known-hosts, and fabric at times won't prompt you for this...

Related

Git bash "Watching for file changes with StatReloader" stuck and never loads

I have setup a Django project on a virtual environment on my PC. When using the command
python manage.py runserver 0.0.0.0:8000
Bit Bash stops doing anything and I have to end the program to start over. I have waited several minutes and when I end the session, a dialogue says:
Processes are running in session:
WPID PID COMMAND
14904 1534 c:\Users\mine\AppData\Loca
Close anyway?
I have looked at every related question to this and tried every solution but I cannot get this to work, on or off the virtual environment.
Not sure if this applies, but I also noticed that in my task manager, python3.9.exe appears twice when trying to start the server. The status says running, and the PIDs are different numbers.
This is because something already running on port 8000. You can run the Django server by hosting on another port like 8080 but, you can also kill the already running task on the port. Follow the link to know how exactly you can kill any running process.
It is highly likely that another application is running using the port 8000. Try running the server using another port, say 8088 and share if the same issue persists.
To run on specific port kill all pids which is showing you on Git bash
(ps -ef)... kill them using (kill -9 pid_no)... then run your runserver command.
Ex:
ps -ef
kill -9 123
I ended up paying someone to fix this. Here is the conversation I had with the person who found the issue. Hope this helps someone out there.
Also, I noticed sometimes it still does freeze up on the watching for file changes with StateReloader until I go the browser and type in http://localhost:8000/. Once I do that the rest of the text loads and my browser shows The install worked successfully! Congratulations!
it works, what did you do?
- We have existing processes on port 8000.I think, you had the server running and kept trying over and over. So, I killed process using 8000 port.
- Next, I run Django project again.
- So, now it's working well.
ok. Can you tell me what you did at the start to make it work? Or was it always working?
- I started git bash session again when I started. Maybe git bash session had problems.
But this was going on for a day, I restarted the computer several times and restarted git bash. Same issue.
You must have done something.
- Sorry, I didn't do anything except restart git bash
how did you restart it?
- right click top of window, select NEW
How do I turn server off?
- press Ctrl + C
- And you didn't quit the server exactly before. Maybe you closed git bash directly and server was still live
- So, we had many 8000 ports.
Ok. How can I see what is on that port now?
- You can use this cli
- netstat -ano | findstr :<PORT>
- We don't have running 8000 port now.
I have never found solutions to this problem even with killing ports, changing port etc.
It never display the following part:
Starting development server at http://127.0.0.1:8000/
However, when I use the Git Bash terminal include into vscode, it displays the url.
Terminal > New Terminal > then:
Result :
python manage.py runserver 127.0.0.1:8080

How to use fabric with ssh keys?

Using fabric 2.4 and trying to set up ssh keys to remotely connect to various linux servers?
Python is new to me, I've followed example on this site and Read python doc but still unclear to me.
Currently running python on windows and my script is able to connect to remote linux servers because i have connection string defined as follows:
ssh_connect = Connection(host='servername', user='user1', connect_kwargs={'password': 'blahblah'})
I am running python script from my window server and instead of defining the connection string, I would like it to use ssh key. I have the id_rsa.pub file from the linux server. I would like to setup up on my windows box and have the script use that for connections?
You can always just pass a key via Fabric through it's command line arguments. This is definitely kind of a vague question, especially since it's running fabric on Windows, which to my knowledge is not technically supported by them, though it does work.
fab -i /Path/to/key
Source: fab --help and the official documentation here

server program exits when i close SSH connection to GCP

I have an Ubuntu instance on Google Cloud Platform (GCP). I want to use it as an HTTP server to access files. I simply use this python command, type it in bash:
python3 -m http.server 8000
This will run http.server module as a script, construct a simple HTTP server and listen at port 8000.
Problem is that, since I use GCP instance, I must connect to it remotely (for example I use SSH shell provided by GCP). When I close the SSH shell, the python HTTP server will stop. So what should I do to make sure that the server still runs after I close the shell?
I did searched on Google, and I tried to use
nohup python3 -m http.server 8000 &
This command, I quote, will run the instruction as a background program and persist running after exiting bash. But it seems that this doesn't work for my situation.
Anybody can help?
Try the screen command. I think it's easier to use and also more flexible than nohup as you can also reattach processes after detaching then. See this answer for details.
The http.server module is not meant to be a full-fledged webserver.
You'll want to set up something like Apache instead, see Running a basic Apache web server.

How to call .ksh file as part of Unix command through ssh in Python

I would like to achieve the following things:
Given file contains a job list which I need to execute one by one in a remote server using SSH APIs and store results.
When I try to call the following command directly on remote server using putty it executes successfully but when I try to execute it through python SSH programming it says cant find autosys.ksh.
autosys.ksh autorep -J JOB_NAME
Any ideas? Please help. Thanks in advance.
Fabric is a good bet. From the home page,
Fabric is a Python (2.5 or higher) library and command-line tool for streamlining the use of SSH for application deployment or systems administration tasks.
A quick example,
>>> from fabric.api import run, env, cd, settings, hide, show
>>> env.host_string='xxx.xxx.com'
>>> env.user='user'
>>> env.password='password'
>>> run('ls -lart')
After reading your comment on the first answer, you might want to create a bash script with bash path as the interpreter line and then the autosys commands.
This will create a bash shell and run the commands from the script in the shell.
Again, if you are using autosys commands in the shell you better set autosys environment up for the user before running any autosys commands.

Python OpenVPN Script

I am attempting to write a python script for linux to start openvpn and have been running into a problem getting openvpn to start using subprocess.
I am using the following to start openvpn:
openvpn_cmd = ['sudo', 'openvpn', '--config', 'client.cfg', '--auth-user-pass', 'hmaauth.conf']
prog = subprocess.Popen(openvpn_cmd)
But I get the following error back from OpenVPN:
Options error: --nobind doesn't make sense unless used with --remote
The config file is downloaded directly from the VPN service website prior to running the subprocess command, so I can't (and shouldn't have to) change anything in the configuration.
I've heard this can happen if you don't run with root privileges, but I'm already doing that...
Does anyone have any suggestions as to why I am getting this error?
I have a working shell script that starts openvpn using the following:
sudo openvpn --config client.cfg --auth-user-pass hmaauth.conf
Which should be exactly what I have in my python script.
Thanks in advance for your advice.
Ok, the problem here is that I'm dumb. I was downloading a config file that didn't have the remote server for the VPN specified, now I understand the 'no remote' error.
Now that I have that cleared up we're good to go.

Categories

Resources