Skip to content

Commit

Permalink
Maintenance: Update to puma 6.
Browse files Browse the repository at this point in the history
This will update from puma 4 to 6, which no longer provides daemonization.
It also removes the deprecated `script/scheduler.rb` wrapper, please use `script/background-worker.rb` instead.
  • Loading branch information
mgruner committed Apr 21, 2023
1 parent c846d5a commit 3e5e059
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 257 deletions.
1 change: 0 additions & 1 deletion .gitlab/ci/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
before_script: []
script:
- shellcheck -S warning $(find . -name "*.sh" -o -name "functions" | egrep -v "/vendor|node_modules/")
- shellcheck -S error script/init.d/*
after_script: []

'lint: i18n & rails':
Expand Down
1 change: 0 additions & 1 deletion .rubocop/todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@ Metrics/BlockLength:
- 'lib/sessions/backend/ticket_overview_list.rb'
- 'lib/sessions/client.rb'
- 'lib/tasks/zammad/search_index_es.rake'
- 'lib/tasks/zammad/ci/service/puma/start.rake'
- 'lib/transaction_dispatcher.rb'
- 'lib/twitter_sync.rb'
- 'script/websocket-server.rb'
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ gem 'composite_primary_keys'
gem 'json'

# core - application servers
gem 'puma', '~> 4', group: :puma
gem 'puma', group: :puma
gem 'unicorn', group: :unicorn

# core - supported ORMs
Expand Down
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ GEM
timeout
net-smtp (0.3.3)
net-protocol
nio4r (2.5.8)
nio4r (2.5.9)
nokogiri (1.14.3)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
Expand Down Expand Up @@ -395,7 +395,7 @@ GEM
binding_of_caller (~> 1.0)
pry (~> 0.13)
public_suffix (5.0.1)
puma (4.3.12)
puma (6.2.2)
nio4r (~> 2.0)
pundit (2.3.0)
activesupport (>= 3.0.0)
Expand Down Expand Up @@ -704,7 +704,7 @@ DEPENDENCIES
pry-remote
pry-rescue
pry-stack_explorer
puma (~> 4)
puma
pundit
pundit-matchers
rack-attack
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ Of course, you can always just start and stop all the processes by hand:
```sh
# in three separate terminal windows
$ rails server
$ script/scheduler.rb start # runs in bg; use -t for fg
$ script/websocket-server.rb start # runs in fg; use -d for bg
$ script/background-worker.rb start
$ script/websocket-server.rb start
```

## Login
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/zammad/ci/app/start.rake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace :zammad do

Rake::Task['zammad:ci:service:puma:start'].invoke(ENV['BROWSER_PORT'], ENV['RAILS_ENV'])
Rake::Task['zammad:ci:service:websocket:start'].invoke(ENV['WS_PORT'])
Rake::Task['zammad:ci:service:scheduler:start'].invoke
Rake::Task['zammad:ci:service:background_worker:start'].invoke
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/zammad/ci/app/stop.rake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace :zammad do

desc 'Stops the application'
task stop: %i[
zammad:ci:service:scheduler:stop
zammad:ci:service:background_worker:stop
zammad:ci:service:websocket:stop
zammad:ci:service:puma:stop
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ namespace :zammad do

namespace :service do

namespace :scheduler do
namespace :background_worker do

desc 'Starts the scheduler'
task :start do # rubocop:disable Rails/RakeEnvironment

command = [
'bundle',
'exec',
'script/scheduler.rb',
'script/ci/daemonize.rb',
'start',
'--',
'background-worker',
'bundle exec script/background-worker.rb start',
]

_stdout, stderr, status = Open3.capture3(*command)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ namespace :zammad do

namespace :service do

namespace :scheduler do
namespace :background_worker do

desc 'Stops the scheduler'
task :stop do # rubocop:disable Rails/RakeEnvironment

command = [
'bundle',
'exec',
'script/scheduler.rb',
'stop',
'script/ci/daemonize.rb',
'start',
'--',
'background-worker',
'bundle exec script/background-worker.rb stop',
]

_stdout, stderr, status = Open3.capture3(*command)
Expand Down
19 changes: 7 additions & 12 deletions lib/tasks/zammad/ci/service/puma/start.rake
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,18 @@ namespace :zammad do
env = args.fetch(:env, 'production')

command = [
'bundle',
'exec',
'script/ci/daemonize.rb',
'start',
'--',
'puma',
'--pidfile',
'tmp/pids/server.pid',
'-d',
'-p',
port,
'-e',
env
"bundle exec puma -p #{port} -e#{env}",
]

_stdout, stderr, status = Open3.capture3(*command)
stdout, stderr, status = Open3.capture3(*command)

next if status.success?
next if status.success? && !stdout.include?('ERROR') # rubocop:disable Rails/NegateInclude

abort("Error while starting Puma - error status #{status.exitstatus}: #{stderr}")
abort("Error while starting Puma - error status #{status.exitstatus}: #{stdout} #{stderr}")
end
end
end
Expand Down
16 changes: 10 additions & 6 deletions lib/tasks/zammad/ci/service/puma/stop.rake
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ namespace :zammad do

desc 'Stops the puma application webserver'
task :stop do # rubocop:disable Rails/RakeEnvironment
file = Rails.root.join('tmp/pids/server.pid')
pid = File.read(file).to_i

Process.kill('SIGTERM', pid)
command = [
'script/ci/daemonize.rb',
'stop',
'--',
'puma',
'bundle exec puma',
]

sleep 5
stdout, stderr, status = Open3.capture3(*command)

next if !File.exist?(file)
next if status.success? && !stdout.include?('ERROR') # rubocop:disable Rails/NegateInclude

Process.kill('SIGKILL', pid)
abort("Error while stopping Puma - error status #{status.exitstatus}: #{stdout} #{stderr}")
end
end
end
Expand Down
32 changes: 32 additions & 0 deletions script/ci/daemonize.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env ruby
# Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/

require 'daemons'

#
# Generic daemonization script for legacy CI tests.
#

def exit_with_usage
puts 'Usage: daemonize.rb start|stop -- $name_of_pidfile $commandline'
exit false
end

dir = File.expand_path(File.join(__dir__, '../..'))

daemon_options = {
multiple: false,
dir_mode: :normal,
dir: File.join(dir, 'tmp', 'pids'),
backtrace: true
}

separator_index = ARGV.index('--')
exit_with_usage if separator_index.nil?
args = ARGV[(separator_index + 1)..]
exit_with_usage if args.count < 2

Daemons.run_proc(args[0], daemon_options) do
Dir.chdir dir
exec(args[1])
end
8 changes: 8 additions & 0 deletions script/init.d/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
This directory used to contain an example init.d script for Zammad installations
without Systemd. This was discontinued since Zammad now uses non-daemonizing service processes.

If using Systemd is not an option for you, consider using the provided binary packages to install
even on systems that don't have Systemd.

Pull requests with a new init script that handles foreground
processes correctly would be welcome as well.
151 changes: 0 additions & 151 deletions script/init.d/zammad

This file was deleted.

Loading

0 comments on commit 3e5e059

Please sign in to comment.