Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a Raku Cro app as a persistent service

Tags:

raku

cro

I'd like to run a perl6/raku Cro app as a service behind a frontend webserver.

Just running cro run won't handle restarting after segfaults & reboots.

Previously with perl5 I've used FastCGI - however Cro::HTTP::Server's Cro::HTTP::Server.new().start() idiom doesn't look compatible with FastCGI::Native's while $fcgi.accept() {} example.

The service.p6 generated by cro stub does have a SIGINT handler, however I'm unsure whether this is sufficient to point to it in a systemctl service, i.e.

[Service]
ExecStart = /path/to/service.p6

How are people currently hosting Cro apps?

like image 278
fireartist Avatar asked Nov 12 '19 15:11

fireartist


1 Answers

cro run is intended as a development tool, not a deployment one, and so is indeed not a good choice for hosting the services.

All of the Cro services I directly take care of are containerized (some guidance on that here) and then run on a hosted Kubernetes cluster. Kubernetes takes care of the automatic restarts, rolling out new versions, etc. I'm also aware of docker-compose being used in place of Kubernetes, which I guess works, though I believe that's also considered as primarily a development tool.

Setting it up as a systemctl service should also work fine, provided that's configured to always restart. However, it seems that you'd want to handle SIGTERM for the clean shutdown to work instead of SIGINT (nothing wrong with handling both).

I do also place a frontend web server in front of Cro (using Apache, though nginx would be a fine choice too), and also use that to do some caching of static content also (using content-control in my routes to describe the cachability).

like image 102
Jonathan Worthington Avatar answered Nov 11 '22 15:11

Jonathan Worthington