perplexed
perplexed

Reputation: 45

Making sense of Ruby server on Cpanel

I have set up a Ruby 3.2 app with cPanel on a hosted system. The rubyhome directory is ruby.myDomain.co.uk. It contains config.ru and app.rb and no html files. A subdirectory of rubyhome is /public which contains two files, index.html and fish.html.

To start the Ruby environment cPanel says I should open a terminal and use source /home/myDomain/rubyvenv/ruby.myDomain.co.uk/3.2/bin/activate but before I do that I use ps aux which shows

USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
myDomain 4075531  0.7  0.0 230360  4188 pts/0    S    04:43   0:00 /bin/bash -l
myDomain 4075646  0.0  0.0 262612  2176 pts/0    R+   04:43   0:00 ps aux

from a browser I call https://www.ruby.myDomain.co.uk/ which serves the file ruby.myDomain.co.uk/public/index.html. If I call fish.html I get ruby.myDomain.co.uk/public/fish.html.

So something somewhere is routing my request to /public & then fulfilling it. I would expect the first call to show a directory listing and the second to return 404.

If I then start the Ruby environment the output of ps aux does not change (although the terminal prompt does). Files are still served as above.

app.rb is

require 'sinatra'
require 'logger'

logger = Logger.new(STDOUT, level: Logger::INFO)
logger.info "Loaded app.rb using  #{settings.public_folder}"

get '/' do
  logger.info "Serving index.html for request: #{request.path_info}"
  send_file File.join(settings.public_folder, 'index.html')
end

on_start do
  puts "===== Booting up app.rb ====="
end
on_stop do
  puts "===== Shutting down ====="
end

If I use ruby app.rb I get

I, [2024-08-28T05:17:13.427851 #4181457]  INFO -- : Loaded app.rb using  /home/myDomain/ruby.myDomain.co.uk/public
/home/myDomain/rubyvenv/ruby.myDomain.co.uk/3.2/gems/sinatra-4.0.0/lib/sinatra/base.rb:1849: warning: Rack::Logger is deprecated and will be removed in Rack 3.2.
[2024-08-28 05:02:42] INFO  WEBrick 1.8.1
[2024-08-28 05:02:42] INFO  ruby 3.2.4 (2024-04-23) [x86_64-linux]
== Sinatra (v4.0.0) has taken the stage on 4567 for development with backup from WEBrick
===== Booting up app.rb =====
[2024-08-28 05:02:42] INFO  WEBrick::HTTPServer#start: pid=4118877 port=4567 

Running ps aux in a second terminal shows

USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
myDomain 4075531  0.0  0.0 230360  4392 pts/0    S    04:43   0:00 /bin/bash -l
myDomain 4118877  0.3  0.0 384520 37380 pts/0    S+   05:02   0:00 /opt/alt/ruby32/bin/ruby app.rb
myDomain 4138701  0.5  0.0 230360  4324 pts/2    S    05:05   0:00 /bin/bash -l
myDomain 4138801  0.0  0.0 262612  2220 pts/2    R+   05:05   0:00 ps aux

Files are still served as before. No request logging is shown.

So I don't know how the files are served, nor by what process, but I don't think my app.rb is doing any routing. Can anyone explain what I'm doing wrong please.

Upvotes: 0

Views: 58

Answers (0)

Related Questions