A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

Webserver experiment 2019

Rough draft notes:


DNS
  • http://freedns.afraid.org
Platform
  • Digital Ocean
  • Ubuntu 16.04
Application container
  • UWSGI
  • https://uwsgi-docs.readthedocs.io/en/latest/Install.html
  • https://uwsgi-docs.readthedocs.io/en/latest/WSGIquickstart.html
  • wget https://projects.unbit.it/downloads/uwsgi-2.0.17.1.tar.gz
  • apt-get install libperl-dev
  • python uwsgiconfig.py --build
  • ./uwsgi --plugins psgi -s :3031 -M -p 4 --wsgi-file /path/to/foobar.py -m # for python. Works
    • But it breaks if you do "python uwsgiconfig.py --plugin plugins/psgi core" afterwards?
    • ./uwsgi: unrecognized option '--wsgi-file'
    • touch buildconf/python.ini
    • python uwsgiconfig.py --build python
      • core/plugins.c:153:35: error: ‘UWSGI_PLUGIN_DIR’ undeclared (first use in this function)
      • plugin_filename = uwsgi_concat3(UWSGI_PLUGIN_DIR, "/", plugin_name);
    • # Rebuilt from scratch and problem went away
  • apt-get install libperl-dev
  • python uwsgiconfig.py --build psgi core
  • python uwsgiconfig.py --plugin plugins/psgi
  • python uwsgiconfig.py --build http
  • python uwsgiconfig.py --plugin plugins/http
  • ./uwsgi --plugins psgi -s :3031 -M -p 4 --psgi /path/to/hello.pl -m # for perl. Fails with...
    • "no python application found"
    • tail -f /var/log/nginx/error.log
    • ./uwsgi --plugins psgi --http-socket 127.0.0.1:3031 --http-socket-modifier1 5 --psgi /path/to/hello.pl
      • Fails with 502 bad gateway after timeout 
      • cat buildconf/http.ini
        • [uwsgi]
        • plugin_dir = .
        • # Rebuild
        • python uwsgiconfig.py --build http
          • ...
          • AttributeError: 'NoneType' object has no attribute 'find'
        • # Try again
          • ./uwsgi --plugins http,psgi --http-socket 127.0.0.1:3031 --http-socket-modifier1 5 --psgi /srv/web1/hello.pl
Webserver Nginx
  • https://uwsgi-docs.readthedocs.io/en/latest/Nginx.html
  • /etc/nginx/sites-available/default
  • location / {
    • uwsgi_pass 127.0.0.1:3031;
    • include uwsgi_params;
  • }
  • nginx -s reload
  • # App should now be available on port 80, via Nginx
  • # Python - works well
  • # Perl - couldn't get it to work
  • # Ruby - to try
Webserver Lighttpd
  • /etc/lighttpd/lighttpd.conf
  • CGI
    • server.modules += ( "mod_cgi" )
    • $HTTP["url"] =~ "/cgi-bin/" {
      • cgi.assign = ( ".pl" => "/usr/bin/perl" )
    • }
    • # Put CGI script in server.document-root + /cgi-bin/
    • # Works
  • PSGI
    • server.modules += ( "mod_scgi" )
    • scgi.protocol = "uwsgi"
    • scgi.server = (
      • "/" => (( "host" => "127.0.0.1", "port" => 3031, "check-local" => "disable" )),
    • )
    • # Doesn't work.
    • Python only?
FastCGI
  • # Try with nginx or lighttpd
  • https://nginxlibrary.com/perl-fastcgi/
Webserver Apache 2
  • # This might be a better choice for Perl

Perl debugger tutorial

If you've never used the Perl debugger before, it is pretty easy when you know how:

1) Add this special breakpoint statement to your script, where you want it to stop so you can look around:
$DB::single = 1;

2) Run the script with -d like this:
perl -d myscript.pl

The script will stop at the first line of code. Press 'c' to continue on to the first breakpoint.

Basic commands:
n = next line (step over any subs)
s = next line (step into any subs)
c = continue

one more command:
v = view lines

There's a trick to make it do 'v' at every step, type this once:
{{v

Instructions:
Step through the script using either 's' or 'n' and make sure it's doing what you think it's doing.

You might get into some gnarly library code at some point. In that case you'll have to either:
a) endure it and keep stepping through until you reach your code on the other side
or
b) set a breakpoint a bit later on, then restart the debugger and keep pressing 'c' until you reach the right place

The difference between 's' and 'n' is, when executing any subroutine call:
- 'n' steps over the subroutine (runs it) and carries on
- 's' steps into the subroutine and you can step through the code inside it

Finally:
You can type any perl statement at the debugger prompt to see what values the variables and things have, for example:
use Data::Dumper;
print Dumper($foo);

Other commands:
q = quit
h = help

See also perldoc perldebug and perldoc perldebtut.

--
Thanks to Nour for being a guinea pig.

Jira tips

Search for all the issues you've viewed recently: /issues/?jql=updated%20%3E%3D%20-52w%20order%20by%20lastViewed%20DESC

Mac top

On a Mac, sort top output by %CPU, descending:

top -o -cpu