2024-10-27 Traveller Subsector Mapper

The Traveller Subsector Mapper is now no longer running under Hypnotoad but under Systemd.

Traveller Subsector Mapper

The main reason I'm doing this is so that systemd can limit the memory available to the app. I'm hoping that this will force Perl to garbage-collect more often and that will show me if I do in fact have memory leaks in the code. I suspect I do, to be honest.

This is what I'm talking about: The web app uses up to 300MiB of RAM. Sure, no problem, there's no need to garbage collect if nobody needs the memory. I still don't like it, though. Probably irrational.

2024-10-27-traveller-1.jpg

Let's hope this works.

The systemd unit:

[Unit]
Description=Traveller
After=network.target
[Install]
WantedBy=multi-user.target
[Service]
Type=simple
WorkingDirectory=/home/alex/farm
Restart=always
DynamicUser=yes
MemoryMax=100M
MemoryHigh=80M
Environment="PERL5LIB=/home/alex/perl5/perlbrew/perls/perl-5.40.0/lib"
ExecStart=/home/alex/perl5/perlbrew/perls/perl-5.40.0/bin/perl \
 /home/alex/farm/traveller.pl \
 daemon --mode production -l http://localhost:4011

I'm using Perlbrew as my user (alex) so this is the tricky part. This unit guarantees that I'm running the app itself using Perl 5.40.0. In the app, I rely on this:

use Mojolicious::Lite -signatures;
use File::Basename;

my $dirname  = dirname($^X);

plugin Mount => {'/traveller' => "$dirname/traveller"};

app->start;

It assumes that App:traveller was installed. It finds the `traveller` script next to the Perl interpreter. If I need to change the Perl version again, I only need to change it in the systemd unit.

App:traveller

The Monit config file no longer needs to know about the Perl version:

check process traveller matching traveller
    start program = "/usr/bin/systemctl start traveller"
    stop program = "/usr/bin/systemctl stop traveller"
    if failed host campaignwiki.org port 443 type tcpssl protocol http
      and request "/traveller" for 5 cycles then restart
    if totalmem > 100 MB for 5 cycles then restart

​#Administration ​#Web ​#Perl ​#Programming

Hex Describe