Failed to start Puma as service - ruby-on-rails

When I lanch the command /home/centos/.rvm/rubies/ruby-3.0.0/bin/bundle exec puma -C /home/centos/app/config/puma.rb in the app folder I get no error :
[145103] Puma starting in cluster mode...
[145103] * Puma version: 5.2.1 (ruby 3.0.0-p0) ("Fettisdagsbulle")
[145103] * Min threads: 1
[145103] * Max threads: 5
[145103] * Environment: production
[145103] * Master PID: 145103
[145103] * Workers: 1
[145103] * Restarts: (✔) hot (✔) phased
[145103] * Listening on unix:///home/centos/app/tmp/sockets/puma.sock
But when I try to start Puma as service service puma start && service puma status I get :
● puma.service - Puma HTTP Server
Loaded: loaded (/etc/systemd/system/puma.service; enabled; vendor preset: disabled)
Active: activating (auto-restart) (Result: exit-code) since Mon 2021-02-15 17:37:24 UTC; 938ms ago
Process: 145289 ExecStart=/home/centos/.rvm/rubies/ruby-3.0.0/bin/bundle exec puma -C /home/centos/app/config/puma.rb (code=exited, st>
Main PID: 145289 (code=exited, status=203/EXEC)
Feb 15 17:37:24 centos-s systemd[1]: puma.service: Main process exited, code=exited, status=203/EXEC
Feb 15 17:37:24 centos-s systemd[1]: puma.service: Failed with result 'exit-code'.
I don't understand why ?

Problem solved, just a too much parenthesis in the config/puma.rb

Related

How do i stop the rails sever?

I run this command to start my server
rails s -b 10.x.x.x
then I got this error
[1013] * Puma version: 5.2.2 (ruby 2.6.3-p62) ("Fettisdagsbulle")
[1013] * Min threads: 2
[1013] * Max threads: 2
[1013] * Environment: development
[1013] * Master PID: 1013
[1013] * Workers: 1
[1013] * Restarts: (✔) hot (✖) phased
[1013] * Preloading application
Exiting
Address already in use - bind(2) for "10.x.x.x" port 3000 (Errno::EADDRINUSE)
How do I stop this current running server 10.x.x.x:3000?
There are several utilities to get the PID of a proccess listening on a port.
lsof -i :3000
Will get you the PID and then you can kill it with kill [PID] or force it with kill -9 [PID]

Rails 6 + Capistrano - No such puma.sock file

please, I have a giant problem for more than 10 hours.
Whenever I run my application deployment in Rails, with Capistrano and Puma, and I run a restart of nginx, I see this error when I try to access my web:
enter image description here
When I access my nginx logs, I see the following error:
2020/12/29 04:09:50 [crit] 9536#9536: *73 connect() to unix:///home/ubuntu/apps/my_app/shared/tmp/sockets/my_app-puma.sock failed (2: No such file or directory) while connecting to upstream, client: [CLIENT_ID], server: , request: "GET / HTTP/1.1", upstream: "http://unix:///home/ubuntu/apps/my_app/shared/tmp/sockets/my_app-puma.sock:/", host: "[MY_HOST]"
2020/12/29 04:09:50 [crit] 9536#9536: *73 connect() to unix:///home/ubuntu/apps/my_app/shared/tmp/sockets/my_app-puma.sock failed (2: No such file or directory) while connecting to upstream, client: [CLIENT_ID], server: , request: "GET / HTTP/1.1", upstream: "http://unix:///home/ubuntu/apps/my_app/shared/tmp/sockets/my_app-puma.sock:/500.html", host: "[MY_HOST]"
Thanks in advance for someone's help. Because it has been over 10 hours that I am trying to solve this problem of missing the ".sock" file and I can't
Update 1:
Following a tutorial I create:
I create in the path: /etc/systemd/system a file: puma-website.service
Inside has:
After=network.target
[Service]
# Foreground process (do not use --daemon in ExecStart or config.rb)
Type=simple
# Preferably configure a non-privileged user
User=ubuntu
Group=ubuntu
# Specify the path to your puma application root
WorkingDirectory=/home/ubuntu/my_app/current
# Helpful for debugging socket activation, etc.
Environment=PUMA_DEBUG=1
#EnvironmentFile=/var/www/my-website.com/.env
# The command to start Puma
ExecStart=/home/ubuntu/.rbenv/shims/bundle exec puma -C /home/ubuntu/my_app/current/config/puma.rb
Restart=always
[Install]
WantedBy=multi-user.target
But I error:
:/etc/systemd/system$ sudo systemctl status puma-website.service
● puma-website.service
Loaded: loaded (/etc/systemd/system/puma-website.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2020-12-29 00:52:19 UTC; 12h ago
Process: 4316 ExecStart=/home/ubuntu/.rbenv/shims/bundle exec puma -C /home/ubuntu/my_app/current/config/puma.rb (code=exited, status=1/FAILURE
Main PID: 4316 (code=exited, status=1/FAILURE)
Dec 29 00:52:19 MyIp systemd[1]: puma-website.service: Main process exited, code=exited, status=1/FAILURE
Dec 29 00:52:19 MyIp systemd[1]: puma-website.service: Failed with result 'exit-code'.
Dec 29 00:52:19 MyIp systemd[1]: puma-website.service: Service hold-off time over, scheduling restart.
Dec 29 00:52:19 MyIp systemd[1]: puma-website.service: Scheduled restart job, restart counter is at 10.
Dec 29 00:52:19 MyIp systemd[1]: Stopped puma-website.service.
Dec 29 00:52:19 MyIp systemd[1]: puma-website.service: Start request repeated too quickly.
Dec 29 00:52:19 MyIp systemd[1]: puma-website.service: Failed with result 'exit-code'.
Dec 29 00:52:19 MyIp systemd[1]: Failed to start puma-website.service.

I am unable to start puma.service using systemd

It has been running well until yesterday. Now, suddenly I cannot get puma running at all. I am currenly using tmux to run puma and run my app. But, it fails when I try to run server using systemctl. Note:- I updated rake and other gems then had to revert back, which gave me error. That I had activated new version of rake, and using older one. So, I decided to install gem 'rubygems-bundler'. Could this have been the cause of the issue?. I have removed this gem now. But, it still doesn't work.
Puma Version: 3.12.0
Here's the puma.service status:
puma.service - Puma HTTP Server
Loaded: loaded (/etc/systemd/system/puma.service; enabled; vendor preset: enabled)
Active: failed (Result: start-limit-hit) since Wed 2020-07-01 12:06:47 UTC; 1s ago
Process: 14640 ExecStart=/home/deploy/.rbenv/shims/puma -C config/puma.rb -p 9100 -e staging (code=exited, status=1/FAILURE)
Main PID: 14640 (code=exited, status=1/FAILURE)
systemd[1]: puma.service: Main process exited, code=exited, status=1/FAILURE
systemd[1]: puma.service: Unit entered failed state.
systemd[1]: puma.service: Failed with result 'exit-code'.
systemd[1]: puma.service: Service hold-off time over, scheduling restart.
systemd[1]: Stopped Puma HTTP Server.
systemd[1]: puma.service: Start request repeated too quickly.
systemd[1]: Failed to start Puma HTTP Server.
systemd[1]: puma.service: Unit entered failed state.
systemd[1]: puma.service: Failed with result 'start-limit-hit'.
My pumar.rb file is:
workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 5)
threads threads_count, threads_count
bind "unix:///tmp/production-puma.sock"
preload_app!
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
on_worker_boot do
# Worker specific setup for Rails 4.1+
ActiveRecord::Base.establish_connection
end
app_path = File.expand_path(File.dirname(__FILE__) + '/../')
stdout_redirect "/#{app_path}/log/puma.stdout.log", "/#{app_path}/log/puma.stderr.log"
Here is puma.service file
[Unit]
Description=Puma HTTP Server
After=network.target
# Uncomment for socket activation (see below)
Requires=puma.socket
[Service]
# Foreground process (do not use --daemon in ExecStart or config.rb)
Type=simple
#Type=forking
# Preferably configure a non-privileged user
User=deploy
# The path to the puma application root
# Also replace the "<WD>" place holders below with this path.
WorkingDirectory=/home/deploy/app
# Helpful for debugging socket activation, etc.
# Environment=PUMA_DEBUG=1
ExecStart=/home/deploy/.rbenv/shims/puma -C config/puma.rb -p 9100 -e staging
Restart=always
[Install]
WantedBy=multi-user.target
Ok. Fixed the issue. It was indeed caused by rubygems-bundler.
Uninstall rubygems-bundler with
gem uninstall rubygems-bundler
My exact issue was not running following command:
executable-hooks-uninstaller
Everything works now.
`

Systemd Rails boot script fails with rbenv, (code=exited, status=1/FAILURE)

After creating a systemd service to launch a rails app, the service is failing with this error:
$ systemctl status evrserver
● evrserver.service - evr server boot
Loaded: loaded (/etc/systemd/system/evrserver.service; enabled; vendor preset: enabled)
Active: activating (auto-restart) (Result: exit-code) since Wed 2019-04-03 18:34:22 BST; 2min 51s ago
Process: 425 ExecStart=/home/pi/.rbenv/bin/rbenv bundle exec rails s -b 192.168.1.66 (code=exited, status=1/FAILURE)
CGroup: /system.slice/evrserver.service
Apr 03 18:34:22 raspberrypi systemd[1]: Failed to start evr server boot.
Apr 03 18:34:22 raspberrypi systemd[1]: evrserver.service: Unit entered failed state.
Apr 03 18:34:22 raspberrypi systemd[1]: evrserver.service: Failed with result 'exit-code'.
Setup based on other online tutorials for systemd starting a rails app in an rbenv managed environment as noted here:
https://gist.github.com/arteezy/5d53d99f6ee617fae1f0db0576fdd418
https://mikewilliamson.wordpress.com/2015/08/26/running-a-rails-app-with-systemd-and-liking-it/
Here is the service file:
[Unit]
Description=evr server boot
After=network.target
After=local-fs.target
[Service]
Type=forking
User=pi
Group=pi
WorkingDirectory=/home/pi/evr
ExecStart=/home/pi/.rbenv/bin/rbenv bundle exec rails s -b 192.168.1.66
TimeoutSec=180
RestartSec=180s
Restart=always
[Install]
WantedBy=multi-user.target
This device has two other services that are custom implementations that are working with no issue, both non rails processes. What am I missing here to have the rails service run?
ah, kinda funny. it's always the little things yeah? forgot an exec before bundle and the type needs to be simple not forking.
[Unit]
Description=evr server boot
After=network.target
After=local-fs.target
[Service]
Type=simple
User=pi
Group=pi
WorkingDirectory=/home/pi/evr
ExecStart=/home/pi/.rbenv/bin/rbenv exec bundle exec rails s -b 192.168.1.66
TimeoutSec=180
RestartSec=180s
Restart=always
[Install]
WantedBy=multi-user.target
and successful logs:
● evrserver.service - evr server boot
Loaded: loaded (/etc/systemd/system/evrserver.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2019-04-04 04:05:45 BST; 8min ago
Main PID: 460 (ruby)
CGroup: /system.slice/evrserver.service
└─460 puma 3.12.0 (tcp://192.168.1.66:3000) [evr]
Apr 04 04:05:45 raspberrypi systemd[1]: Started evr server boot.
Apr 04 04:06:08 raspberrypi rbenv[460]: => Booting Puma
Apr 04 04:06:08 raspberrypi rbenv[460]: => Rails 6.0.0.beta3 application starting in development
Apr 04 04:06:08 raspberrypi rbenv[460]: => Run `rails server --help` for more startup options
Apr 04 04:13:51 raspberrypi rbenv[460]: Puma starting in single mode...
Apr 04 04:13:51 raspberrypi rbenv[460]: * Version 3.12.0 (ruby 2.6.2-p47), codename: Llamas in Pajamas
Apr 04 04:13:51 raspberrypi rbenv[460]: * Min threads: 5, max threads: 5
Apr 04 04:13:51 raspberrypi rbenv[460]: * Environment: development
Apr 04 04:13:51 raspberrypi rbenv[460]: * Listening on tcp://192.168.1.66:3000
Apr 04 04:13:51 raspberrypi rbenv[460]: Use Ctrl-C to stop

Restarting Puma in Ubuntu

Why must I restart Puma twice in Ubuntu for it to work?
# uname -a
Linux myapp 3.11.0-12-generic #19-Ubuntu SMP Wed Oct 9 16:20:46 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
# pumactl -v
2.6.0
# pumactl -S /home/myapp/tmp/puma.state restart --config /home/myapp/config/puma.rb
Command restart sent success
[...that's not working, Puma is still running...]
# pumactl -S /home/myapp/tmp/puma.state restart --config /home/myapp/config/puma.rb
[9703] Puma starting in cluster mode...
[9703] * Version 2.6.0, codename: Pantsuit Party
[9703] * Min threads: 0, max threads: 16
[9703] * Environment: production
[9703] * Process workers: 2
[9703] * Phased restart available
[9703] * Listening on unix:///home/myapp/tmp/puma.sock
[9703] * Daemonizing...
[...ok now it worked...]
I wouldn't trust this pumactl script. Just use kill -SIGUSR2 <pid> as recommended in the puma documentation itself : https://github.com/puma/puma.

Resources