uWSGI as a standalone http server with lua - lua

I'm trying to set up uWSGI to run as a standalone server running a simple LUA script(right now, as a POC, using the hello world from http://uwsgi-docs.readthedocs.org/en/latest/Lua.html).
Here's my uwsgi.ini file:
[uwsgi]
master = true
workers = 1
threads = 8
listen = 4096
max-request = 512
pidfile = /uwsgi/logs/uwsgi.pid
procname-master = uWSGI master
auto-procname = true
lua = /uwsgi/hello.lua
socket-timeout = 30
socket = /uwsgi/uwsgi_1.sock
http = 127.0.0.1:80
http-to = /uwsgi/uwsgi_1.sock
When sending a web request, an empty response is received, and uWSGI process outputs:
-- unavailable modifier requested: 0 --
I've read this usually means a plugin is missing, however, LUA plugin is installed, and when doing the same but through NGINX everything works fine, which means there's no problem loading LUA.
Any help please?
Thanks.

Somebody told me I had to add http-modifier1 = 6 and now it works.
Still don't understand what does '6' mean, but whatever.

Related

Lua resty_dogstatsd only publishes first instance

I have a metric client that looks something like:
package.path = package.path .. ';../?.lua'
local metrics = {}
local resty_dogstatsd = require('resty_dogstatsd')
local logger = require('module.utils.logger')
local _statsd = resty_dogstatsd.new({
statsd = {
host = config.dataDog.host,
port = config.dataDog.port,
namespace = config.dataDog.namespace
},
tags = config.dataDog.tags
})
function metrics.incMetric1 ()
logger.debug('Updating metric metric1');
_statsd:increment(metric1 1, 1)
end
return metrics;
Then in my application I import it and use it
local metrics = require('module.metrics')
-- somewhere, some condition
metrics.incMetric1()
This publishes the log Updating metric metric1 in datadog and I can see it. But this will only publish the first instance. Until I restart service nginx restart, I will not get any more increments.
Update
So I have a start.lua in /etc/nginx/conf.d/start.lua that is:
package.path = package.path .. ';/path/to/my/app/?.lua'
local app = require('app.init');
app.start()
And the nginx config is
rewrite_by_lua_file /etc/nginx/conf.d/start.lua;
If I were to copy/paste the metric code into start.lua, then the metric is updated every time. Why is this?!
Update
I noticed this in the error logs:
2018/05/23 10:02:07 [error] 24483#0: *6 attempt to send data on a closed socket: u:some-hex, c:some-hex, client: 123.12.0.123, server: *.my-url.com, request: "GET / HTTP/1.1", host: "my.my-url.com"
This happens on the 2nd request to the nginx; the first time after restart, this is all fine ...
Update 2
This happens only if I have a metrics file and require it in my other. So if I instantiate the resty_dogstatsd client inside the main lua file, then everything is fine ...

Yaws code inside <erl></erl> not running

I am trying out Yaws, however I have run into a bump. The code inside my .yaws file is not compiling when I got to the path, instead it is being printed on the window. Here is my code and configuration:
<erl>
method(Arg) ->
Rec = Arg#arg.req,
Rec#http_request.method.
out(Arg) ->
{ehtml, f("Method: ~s", [method(Arg)])}.
</erl>
Server configuration:
<server localhost>
port = 8000
listen = 127.0.0.1
docroot = /home/something/
dir_listings = true
dav = true
auth_log = true
statistics = true
</server>
Any info would really be appreciated, thank you.
The problem is that you have dav = true in your server configuration, which turns on WebDAV, a protocol for content management. Under this configuration, a .yaws file is treated as just a regular file, not as one that requires special Yaws processing, which is why you see the verbatim contents of the file when you access it via your browser.
Removing dav = true from your configuration and then restarting Yaws will make it process your example.yaws file as you expect.

Route uwsgi logs by HTTP method (HEAD/GET/etc)

I'm using uwsgi behind nginx, monitored by monit.
Monit checks the status of the site by (by default) sending a HEAD / HTTP/1.1 request. This works fine, but I end up with an awful lot of these lines in the logfile:
[pid: 28317|app: 0|req: 1/1] xxx.ip.addr.xxx () {34 vars in 366 bytes} [Wed Aug 2 16:17:58 2017] HEAD / => generated 0 bytes in 13 msecs (HTTP/1.1 200) 2 headers in 81 bytes (0 switches on core 0)
It looks like log-route and log-req-route are designed for this, see the docs and other questions on this site, but I can't seem to route HEAD requests to their own file.
My uwsgi.ini:
# Log Monit pings separately
req-logger = monitrequests file:uwsgi-monitrequests.log
# All other requests
req-logger = file:uwsgi-requests.log
# Everything else
logger = file:uwsgi.log
log-req-route = monitrequests .*HEAD.*
All the logged requests just end up in uwsgi-requests.log.
One work-around could be to have Monit probe a health-check url (e.g. my.site/heartbeat) and have uwsgi route based on that, are there any better options?

How to rebuild uwsgi with xml = True

I have installed uwsgi in my server. But when I can't use command uwsgi -x django_socket.xml.
It said
uwsgi: invalid option -- 'x'
getopt_long() error
Someone told me that i should rebuild it cause i build uwsgi without xml support. Then i check the uwsgi docs.
Then i downloads the Django-2.0.4.tar.gz again, cause i remove it after i installed it last time.
And i rebuild it with command:
python uwsgiconfig.py --build
And i saw a report
pcre = True
kernel = Linux
malloc = libc
execinfo = False
ifaddrs = True
ssl = True
zlib = True
locking = pthread_mutex
plugin_dir = .
timer = none
yaml = embedded
json = False
filemonitor = inotify
routing = True
debug = False
capabilities = False
xml = False
event = epoll
but it seems does't work, the xml still false. What should i do?
install libxml2 or expat development headers and re-run make. The build system will automatically detect their availability

HHVM+Hacklang: errors/warnings output into browser

Is there any way to tell HHVM to output Hacklang warnings and errors into the browser? Something like PHP does with enabled display_errors, display_startup_errors and error_reporting set to E_ALL
HHVM version:
$ php -v
HipHop VM 3.1.0-dev+2014.04.09 (rel)
Compiler: heads/master-0-g4fc811c64c23a3686f66a2bea80ba47f3eaf9f3d
Repo schema: 79197c935790c0b9c9cb13566c3e727ace368117
I've tried the following config:
$ cat /etc/hhvm/php.ini
; php options
display_startup_errors = On
error_reporting = E_ALL
display_errors = On
; hhvm specific
hhvm.log.level = Warning
hhvm.log.always_log_unhandled_exceptions = true
hhvm.log.runtime_error_reporting_level = 8191
hhvm.mysql.typed_results = false
And :
$ cat /etc/hhvm/server.ini
; php options
pid = /var/run/hhvm/pid
; hhvm specific
hhvm.server.port = 9000
hhvm.server.type = fastcgi
hhvm.server.default_document = index.php
hhvm.log.level = Warning
hhvm.log.always_log_unhandled_exceptions = true
hhvm.log.runtime_error_reporting_level = 8191
hhvm.log.use_log_file = true
hhvm.log.file = /var/log/hhvm/error.log
hhvm.repo.central.path = /var/run/hhvm/hhvm.hhbc
hhvm.mysql.typed_results = false
hhvm.debug.full_backtrace = true
hhvm.debug.server_stack_trace = true
hhvm.debug.server_error_message = true
hhvm.debug.translate_source = true
tl;dr: You can't.
The thing to keep in mind here is that the typechecker does a static analysis of your code while the PHP errors you talk about show up at runtime. If this was C++, you could compare the Hack typechecker errors with the errors during the compile step - so Hack tells you things that are wrong before the code even runs.
The trick is to use either the vim or emacs plugins which warn you of errors as you save the file, or use hh_client from the terminal, or build a plugin for your favorite IDE (feel free to send pull requests!). hh_client --json gives an easy to parse output if you want to build a plugin for Sublime Text, or Eclipse or whatever you want.
Note that some errors are runtime errors, while some aren't. Function args as well as return types should throw exceptions at runtime for the latest HHVM build for example. The problem there is that you only see those errors when you hit a certain code-path. The beauty of Hack is that it errors for all the problems in your code, even if it's a code-path you may not test at runtime.

Resources