WLST disconnect command issue - python

I had ran wlst.cmd in my local system after I ran my Weblogic Admin Instance. But as WLST is stateful, I am getting connected to my IT env which is my Integration Testing environment (some UNIX machine for my project). I tried disconnect() to goto offline mode, however it is failed.
wls:/beaProjDir/serverConfig> disconnect()
You will need to be connected to a running server to execute this command
Please help to go offline mode in WLST. As I need to get some work done in my local system.

You can try to getting out of WLST Shell ctrl+D. Which is similar to exiting from any other shell.

Related

Pytest/Fabric not using SSH agent when debugging in PyCharm

I am writing some infrastructure tests using pytest and fabric. Generally this is working. I run a test from the command line that executes a fabric task on a remote server and asserts something about the result of that task. The task is executed using my running SSH agent.
However, when I try to debug my tests in PyCharm the fabric tasks fail with the following exception
Fatal error: Needed to prompt for a connection or sudo password, but input would be ambiguous in parallel mode
This difference in behavior leads me to believe something isn't configured properly in my debug configuration. I have made sure that environment variables in debug config includes the SSH agent PID.

How to remote debug in PyCharm

The issue I'm facing right now:
I deploy Python code on a remote host via SSH
the scripts are passed some arguments and must be ran by a specific user
the PyCharm run/debug configuration that I create connects through SSH via a different user (can't connect with the user that actually runs the scripts)
I want to remote debug this code via PyCharm...I managed to do all configuration, I just get permission errors.
Are there any ways on how I can run/debug the scripts as a specific user (like sudo su - user)?
I've read about specifying some Python Interpeter options in PyCharm's remote/debug configuration, but didn't manage to get a working solution.
If you want an easy and more flexible way to get into the PyCharm debugger, rather than necessarily having a one-click "play" button in PyCharm, you can use the debug server functionality. I've used this in situations where running some Python code isn't as simple as running python ....
See the Remote debug with a Python Debug Server docs for more details, but here's a rough summary of how it works:
Upload & install remote debugging helper egg on your server (On OSX, these are found under /Applications/PyCharm.app/Contents/debug-eggs)
Setup remote debug server run configuration: click on the drop-down run configuration menu, select Edit configurations..., hit the + button, choose Python remote debug.
The details entered here (somewhat confusingly) tell the remote server running the Python script how to connect to your laptop's PyCharm instance.
set Local host name to your laptop's IP address
set port to any free port that you can use on your laptop (e.g. 8888)
Now follow the remaining instructions in that dialog box: copy-paste the import and pydevd.settrace(...) statements into your code, specifically where you want your code to "hit a breakpoint". This is basically the PyCharm equivalent of import pdb; pdb.set_trace(). Make sure the changed code is sync'ed to your server.
Hit the bug button (next to play; this starts the PyCharm debug server), and run your Python script just like you'd normally do, under whatever user, environment etc. When the breakpoint is hit, PyCharm should drop into debug mode.
I have this (finally) working with ssh RemoteForward open, like so:
ssh -R 5678:localhost:5678 user#<remotehost>
Then start the script in this ssh session. The python script host must connect to localhost:5678 and of course your local pycharm debugger must listen to 5678
(or whatever port you choose)

Connection interrupted when run "indirectly". Bottle.py on Ubuntu

I'm running a local web service on Ubuntu on localhost:8090, written with bottle.py.
The connection uses SSL.
If I execute the main.py file from Nautilus or the terminal and connect to https://localhost:8090 everything works fine.
When I execute it from a link to the file, an .sh script or a .desktop file the server starts running fine, but when I browse to the address firefox says "The connection to localhost:8090 was interrupted while the page was loading"
$telnet 127.0.0.1 8090 gives this:
Trying 127.0.0.1...
Connected to 127.0.0.1...
Escape character is '^]'.
Connection closed by foreign host.
$sudo netstat -ntlupp | grep 8090 gives this:
tcp 0 0 127.0.0.1:8090 0.0.0.0:* LISTEN
iptables is default
I've got the feeling it's blocking the connection when the server is executed "indirectly" (link, script or .desktop), since when I actually click on the file or run it through terminal it runs fine.
I don't have a clue on where to prevent it from blocking the connection, though. Any help is greatly appreciated.
Any workaround will do, even just pretending the file is being run directly from the user.
Thanks in advance
Watch the server logs.
The major difference between the different methods of invocation probably is the current working directory.
I think that it is unlikely that the network configuration is involved in what you are observing.
Depending on the complexity of your web application it might be that a Python import fails if the main script is not run from the right directory. This would trigger a Python exception, which might lead to an immediate connection reset. I have not worked with bottle, but other Python web frameworks distinguish a development mode in which Python tracebacks are shown in the browser, and a production mode in which an HTTP error is sent to the client.
This is what you should do in order to debug your issue: run your server from a terminal (cd to the right directory, then run python application.py). Carefully watch stdout and stderr of that server process while connecting to the web application with your browser.
Ok, problem solved.
It was actually depending on the current working directory not being the same as the python file running the WSGI server.
If I run the .sh script or the link from the same directory everything works fine, and if I give a cd command in the script everything works smoothly.
Thanks for the help Jan-Philip!

different behavior in Python shell and program

I'm using subprocess.Popen to instantiate an ssh-agent, add a key and push a git repository to a remote. To do this I string them together with &&. The code I'm using is
subprocess.Popen("eval $(ssh-agent) && ssh-add /root/.ssh/test_rsa && git push target HEAD", shell=True)
When I run this as a .py file I am prompted for the key's password. This seems to work as I get.
Identity added: /root/.ssh/test_rsa (/root/.ssh/test_rsa).
But when it tries to push the repository to the remote, an error occurs.
ssh: connect to host ***.***.***.*** port 22: Connection refused
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
However, if I simply run the same command in the interactive shell, it works. What causes this difference in behaviour, and what can I do to fix this?
The git server was on an aws instance that was being started earlier in the script. There was a check to make sure it was running, but aws seems to report an instance as running once boot has begun. This means that there is a brief time in which the instance is running, but an ssh daemon doesn't exist. Because the script moved very quickly into trying to push, it was falling within this time period and the server was refusing its connection attempt. By the time I would try anything in the interactive shell the instance was running long enough that it was working.
In short, aws says instances are running before the OS has started services.

File disappears when not ssh'd

So I have tornado server setup on my vps running ubuntu 12.04. So when I am ssh'd into my server or am vnc'd in there the site loads static/templates files just fine. But when I exit out of ssh or terminate vnc python throws error that the file it was looking for does not exist.
[Errno 2] No such file or directory
When I execute the server I just run the python command to run it as a background process, and once its successfully running and exit out.
I have the server running at www.calapp.manangandhi.com
Edit: As per the answer below I was able to figure out a way for it to work. here si the link to daemonizing tornado application, there are other ways suggested in the thread as well. https://groups.google.com/forum/?fromgroups=#!topic/python-tornado/4cxKEFsS0RE
Are you trying to say that you run the server from within the ssh shell? If so, your problem is most likely that on shutdown of the shell, the software gets a HUP and disconnects despite being in the background. You need the software to daemonize and detach completely from the running terminal. If you're using a toolkit, look up "starting as daemon" or launch your software from within DJB's supervise or other system-wide launcher system.

Categories