I really appreciate all the help I've received on this thread! The Racket 
community has been fantastic.

I have my proof-of-concept working for the web infrastructure - no need for 
a Unicorn/Puma-like app, no need for monit, no need to daemonize - just 
systemd to manage N Racket processes, and nginx in front to reverse proxy 
to the Racket workers.

I ended up with this systemd service file:

--- snip ---
[Unit]
Description=Racket hello world %i

[Service]
WorkingDirectory=/home/deploy/appname/current/
ExecStart=/usr/local/bin/racket /home/deploy/appname/current/hello.rkt %i
Restart=always

[Install]
WantedBy=multi-user.target
--- snip ---

Enable 2 workers:  sudo systemctl enable hello@{1..2}
Start them: sudo systemctl start hello\@{1..2}
Check status:  sudo systemctl status hello\@{1..2}

They auto start at boot time, and they auto restart if killed or they crash.

I hacked up a quick test using a command line argument to specify the port 
and log file (I know there are more elegant solutions, but I was in a hurry 
to verify it).  It's possible that using a single log file for all the 
workers will "just work", but I wasn't sure, so I use one log file per 
process for now. I suppose there are pros/cons to each approach.

(module+ main
    (define instance-id (string->number (vector-ref 
(current-command-line-arguments) 0)))
    (define port (+ 8000 instance-id))
    (serve/servlet
          dispatcher
          #:log-file (format "hello~a.log" instance-id)
          #:stateless? #t
          #:port port
          #:command-line? #t
          #:file-not-found-responder not-found
          #:launch-browser? #f
          #:servlet-regexp #rx""))

nginx config includes:

--- snip ---
...
  upstream racket {
    least_conn;
    server localhost:8001;
    server localhost:8002;
  }
...
proxy_pass http://racket;
--- snip ---

Now I can get on to the fun part of porting my Ruby/Rails app, and then 
extending it.


On Thursday, November 29, 2018 at 5:17:38 PM UTC-5, Philip McGrath wrote:
>
> To give you an example, here's a very basic systemd file that I use to run 
> a Racket web server: 
>
> /etc/systemd/system/ricoeur-portal.service
> [Unit]
> Description=Digital Ricoeur portal web server
>
> [Service]
> User=ricoeurd
> Group=ricoeurd
> AmbientCapabilities=CAP_NET_BIND_SERVICE
> WorkingDirectory=/home/ubuntu/ricoeur-portal/
> ExecStart=/usr/local/bin/ricoeur-portal --production
>
> [Install]
> WantedBy=multi-user.target
>
> It's particularly nice from a security perspective that 
> `CAP_NET_BIND_SERVICE` makes it easy to run as a user with minimal 
> privileges and still be able to bind to ports 80 and 443.
>
> -Philip
>
>
> On Thu, Nov 29, 2018 at 5:09 PM Alex Harsanyi <alexha...@gmail.com 
> <javascript:>> wrote:
>
>>
>>
>> On Thursday, November 29, 2018 at 11:17:38 PM UTC+8, Brian Adkins wrote:
>>>
>>> I'm running Ubuntu 18.04 LTS, so I do have systemd. Just to clarify, are 
>>> you stating that systemd will take a program designed to run as a 
>>> foreground process and run it in the background automatically? 
>>>
>>
>> Yes.
>>  
>>
>>> I was planning on using monit to monitor/restart/etc. a set of Racket 
>>> processes, but maybe systemd will do everything I need such as restarting 
>>> one if it crashes.
>>>
>>> On Wednesday, November 28, 2018 at 10:45:59 PM UTC-5, Alex Harsanyi 
>>> wrote:
>>>>
>>>>
>>>> If your Linux installation has systemd, you can create a service file 
>>>> for your application -- this way, systemd will manage the application as a 
>>>> server or daemon.  Systemd will even redirect stderr messages to the 
>>>> system 
>>>> log.
>>>>
>>>> Alex.
>>>>
>>>> On Thursday, November 29, 2018 at 10:56:25 AM UTC+8, Brian Adkins wrote:
>>>>>
>>>>> I briefly looked at the daemonize package on Ubuntu linux, but 
>>>>> couldn't get it to work properly. I found the following Rosetta Code page:
>>>>>
>>>>> https://rosettacode.org/wiki/Run_as_a_daemon_or_service#Racket
>>>>>
>>>>> So, I just tried the code in that example, and it seems to work fine:
>>>>>
>>>>> (module+ main
>>>>>         * ((get-ffi-obj 'daemon #f (_fun _int _int -> _int)) 0 0)*
>>>>>          (serve/servlet
>>>>>           dispatcher
>>>>>           #:log-file "hello.log"
>>>>>           #:stateless? #t
>>>>>           #:port 6995
>>>>>           #:command-line? #t
>>>>>           #:file-not-found-responder not-found
>>>>>           #:launch-browser? #f
>>>>>           #:servlet-regexp #rx""))
>>>>>
>>>>> I'm just wondering if there is a better way to accomplish this since 
>>>>> it feels a bit kludgy to me.
>>>>>
>>>>> Thanks,
>>>>> Brian
>>>>>
>>>>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to racket-users...@googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to