Uwsgi server must execute in script path else I get a http 500 response - uwsgi

I can't understand why I am getting a http 500 response. When I run my uwsgi server from the path that my python script is defined in, everything is perfect. As soon as I run it from another path, I get a 500 response.
Here is my uwsgi script (I set the protocol to http just for testing purposes):
/home/baz/.virtualenvs/python-flask-benchmark/bin/uwsgi
--master
--socket 127.0.0.1:3031
--pythonpath "/home/baz/Personal/Github/benchmark-node_vs_python/python"
--file "/home/baz/Personal/Github/benchmark-node_vs_python/python/app.py"
--callable app
--processes 20
--virtualenv "/home/baz/.virtualenvs/python-flask-benchmark"
--enable-threads
--protocol http
Does anyone know why? It seems like it is ignoring the --pythonpath argument.

Okay, figured it out. It was a path error whereby my application could not find a file to open. The problem was that this was not logged to Uwsgi, which was just silent. The reason was because this was a flask application, which needs to be instructed to pass all exception errors to uwsgi by doing this: app.config['PROPAGATE_EXCEPTIONS'] = True

Related

Docker: 502/503 errors, waiting for response to warmup request for container

I have a web app in a Docker container that works perfectly if I run it locally, but when I deploy it to Azure it just won't work, whatever I try. I keep getting 502/503 errors. In the log file it says:
Traceback (most recent call last):
[ERROR] File "app.py", line 22, in
[ERROR] app.run(use_reloader=use_reloader, debug=use_reloader, host=host, port=port)
[ERROR] File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 922, in run
[ERROR] run_simple(t.cast(str, host), port, self, **options) [ERROR] File "/usr/local/lib/python3.6/site-packages/werkzeug/serving.py", line 982, in run_simple
[ERROR] s.bind(server_address)
[ERROR] socket.gaierror: [Errno -2] Name or service not known
The configuration I have:
Dockerfile: EXPOSE 80, application settings: see picture, app runs with this python code (this is just a snippet to show how environment variables are called):
if __name__ == '__main__':
# Get environment variables
use_reloader = os.environ.get('use_reloader')
debug = os.environ.get('debug')
port = os.environ.get('port')
# Run the app
app.run(use_reloader=use_reloader, debug=use_reloader, host=host, port=port)
What am I missing here? I looked at other answers related to this on here but that didn't help me with this. Anyone any suggestions? Thanks!
EDIT:
I tried another attempt, now with in Dockerfile: EXPOSE 8000, and in application settings: port 80 (see code snippet app.py above) and WEBSITES_PORT 8000. But now I get: Waiting for response to warmup request for container. And then after many of these messages it times out and restarts... I think I still don't understand quite how it works with the port settings, would someone be able to explain this to me? So what I need to know: how don the environment variable 'port' in app.py, the EXPOSE in the Dockerfile and the settings 'port' and 'WEBSITES_PORT' in the application settings in the web app need to be aligned/configured? I just can't find clear information about this.
I resolved the issue myself: the reason for the errors was that I had a huge image (with BERT model) but using a basic app plan. I upgraded to P1V3 and now it runs like a charm, with WEBSITES_PORT=8000 and WEBSITES_CONTAINER_START_LIMIT=1200. Please allow 2 minutes to warm up.

Cloud9 Rails API challenge: allowed network but still cannot render console

I am following along with this Treehouse Build a Rails API course. I am using Cloud9 IDE which I think is related to the problem. The step I am stuck on is creating a new list via the API in the console.
At first I was receiving an error message saying "cannot render console" from the network. After googling this, I whitelisted the network in the development.rb file. The error message is different and so I believe I properly whitelisted it (or at least did something). But it does not have the desired effect and the error message seems to contradict itself.
Started POST "/api/lists" for 123.456.78.999 at 2015-09-14 14:53:33 +0000 Cannot render console from 123.456.78.999! Allowed networks: 123.456.78.999, 127.0.0.0/127.123.123.123, ::1
I've changed the numbers because I am not savvy about security. The point (and to me, the mystery) is that it says I can't render the console from a network that is apparently allowed (i.e., 123.456.78.999 === 123.456.78.999).
I would appreciate any advice on what could be the problem. I had no trouble following along with the tutorial until this step; the commands I entered led to the same result as in the videos.
This is the most recent command I've entered:
curl -i -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"title":"The Title will go here"}' https://myapp-me.c9.io/api/lists
Entering that URL instead of "localhost" has worked for me thus far but it could also be related to the problem.
Thank you for any clues and happy to post additional code if needed.
please add in config/enviroments/development.rb
config.web_console.whitelisted_ips = '0.0.0.0/0.0.0.0'
To whitelists 2 IPs > Consider this example:
config.web_console.whitelisted_ips = %w( 127.0.0.1 10.0.0.9 )
To whitelist an entire IP subnet > Consider this example:
config.web_console.whitelisted_ips = %w( 127.0.0.1 10.0.0.0/24 )
always add 127.0.0.1, or else the local machine won't have access.
If anyone is still viewing this question in 2022 like I am, then you can edit config/environments/development.rb to account for the entire private network like so:
Rails.application.configure do
.
.
.
config.web_console.permissions = '123.456.78.0/16'
end
More information here.
Part of the problem is that you need to be within the "sudo su" shell in order to run Ruby on Rails applications. So, make sure that you run sudo su and you become root. The second problem is that you MUST run your application on port 8080 so when you run the server make sure the -p 8080 flag is set:
bundle update (optional)
bundle install (optional)
sudo su
rails s -p 8080
New terminal --> Preview --> Preview running application

lost logout functionality for grails app using spring security

I have a grails app that moved to a new subnet with a change to the DNS. As a result, the logout functionality stopped working. When I inspect the network using chrome, I get this message under request headers: CAUTION: Provisional headers are shown.
This means request to retrieve that resource was never made, so the headers being shown are not the real thing.
The logout function is executing this action
package edu.example.performanceevaluations
import org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils
class LogoutController {
def index = {
// Put any pre-logout code here
redirect uri: SpringSecurityUtils.securityConfig.logout.filterProcessesUrl // '/j_spring_security_logout'
}
}
Would greatly appreciate a direction to look towards.
As suggested by that link run chrome://net-internals and see if you get anywhere
If you are still lost, I would suggest a two way debugging if you have Linux find something related to your traffic and run either something like tcpdump or if thats too complex install and run ngrep -W byline -d any port 8080 -q. and look for the pattern see what is going on.
ngrep/tcpdump and look for that old ip or subnet on entire traffic see if anything is still trying get through - (this all be best on grails app server ofcourse
(unsure possibly port 8080 or any other clear text port that your app may be running on)
Look for your ip in the apache logs does it hit the actual server when you log out etc?
Has the application been restarted since subnet change since it could have cached the next point from application in the running Java process:
pgrep java|awk '{print "netstat -plant "$1" |grep "$1 }'|/bin/sh
or
pgrep java|awk '{print " lsof -p "$1" |grep -i listen"}'|/bin/sh
I personally think something somewhere needs to be restarted since its hooking on to a cache of something .
Also check the hosts files of any end machines involved ensure nothing has previous subnet physically configured in there.

Icinga check_jboss "NRPE: unable to read output"

I'm using Icinga to monitor some servers and services. Most of them run fine. But now I like to monitor a JBoss-AS on one server via NRPE. Therefore I'm using the check_jboss-Plugin from MonitoringExchange. Although each time I try running a test-command from my Icinga-Server via NRPE I'm getting a NRPE: unable to read output error. When I try executing the command directly on the monitored server it runs fine. It's strange that the execution on the monitored server takes around 5 seconds to return a acceptable result but the NRPE-Exceution returns immediately the error. Trying to set up the NRPE-timeout didn't solve the problem. I also checked the permissions of the check_jboss-plugin and set them to "777" so that there should be no error.
I don't think that there's a common issue with NRPE, because there are also some other checks (e.g. check_load, check_disk, ...) via NRPE and they are all running fine. The permissions of these plugins are analog to my check_jboss-Plugin.
Following one sample exceuction on the monitored server which runs fine:
/usr/lib64/nagios/plugins/check_jboss.pl -T ServerInfo -J jboss.system -a MaxMemory -w 3000: -c 2000: -f
JBOSS OK - MaxMemory is 4049076224 | MaxMemory=4049076224
Here are two command-executions via NRPE from my Icinga-Server. Both commands are correctly
./check_nrpe -H xxx.xxx.xxx.xxx -c check_hda1
DISK OK - free space: / 47452 MB (76% inode=97%);| /=14505MB;52218;58745;0;65273
./check_nrpe -H xxx.xxx.xxx.xxx -c jboss_MaxMemory
NRPE: Unable to read output
Does anyone have a hint for me? If further config-information needed please ask :)
Try to rule out SELinux either by disabling it globally or by changing the SELinux type to nagios_unconfined_plugin_exec_t.

YAWS Websocket Trouble

I'm trying to get the YAWS websocket example from here running on my local. It's a basic ws-based echo server.
I have
YAWS set up and running on localhost:8080 (direct from the Debian repos; no conf changes except pointing it to a new root directory)
the code listing from the bottom of this page wrapped in <erl> tags saved as websockets_example_endpoint.yaws
this page saved as index.yaws (I literally copy/pasted the view-source for it, saved it as that file and pointed the socket request at localhost:8080 rather than yaws.hyber.org).
When I visit localhost:8080/websockets_example_endpoint.yaws in-browser, it displays the text "You're not a web sockets client! Go away!", as expected. When I visit localhost:8080, it points me to the javascript enabled form, but the "Connect" button does nothing when clicked. If I leave index.yaws pointed at yaws.hyber.org instead of localhost:8080, the echo server connects and works exactly as expected.
Can anyone give me a hint as to what I'm doing wrong (or alternatively, point me to source for a working example)?
There is a gitbub project, I've created:
https://github.com/f3r3nc/yaws-web-chat/
This is also an example for embedding yaws and extended with group chat.
Note, that the standard of WebSocket is under development thus yaws and the browser should support the same WS version in order to work correctly.
yaws 1.91 works with Safari Version 5.1.1 (6534.51.22) but does not with Chrome (15.0.874.102) and probably not with (14.x).
For me the problem was I did not have the basic_echo_callback module file because I installed yaws using a package repository rather than building form source.
The error was evident if running yaws in interactive mode ´yaws -i´:
=ERROR REPORT==== 7-Dec-2016::21:33:49 ===
Cannot load callback module 'basic_echo_callback': nofile
=ERROR REPORT==== 7-Dec-2016::21:33:49 ===
Failed to start websocket process: nofileq
This is pretty much my process from scratch on Ubuntu 16.01:
sudo apt install yaws
cd ~
mkdir yaws
cd yaws
mkdir src
cd src
cd src wget https://github.com/klacke/yaws/raw/master/examples/src/basic_echo_callback.erl
cd ..
mkdir www
cd www
wget https://raw.githubusercontent.com/klacke/yaws/master/www/websockets_example_endpoint.yaws
wget http://yaws.hyber.org/websockets_example.yaws
cd ..
#set-up server config file...
vim yaws.conf
Mine looks like:
src_dir = /home/pocketsand/yaws/src
<server localhost>
port = 8000
listen = 127.0.0.1
docroot = /home/pocketsand/yaws/www
</server>
Ensure endpoint is correct in the client:
vim www/websockets_example.yaws
...
Stop server if already running and start server with ´yaws -i´ and browse to: http://localhost:8000/websockets_example.yaws
It works because each time the server loads the configuration file it will compile any modules in the specified src directory. If other modules are missing for the other features they will also need to be downloaded.

Resources