Skip to content

Commit 4d4718f

Browse files
authored
Implement graceful shutdown for recording importer on SIGTERM/SIGINT (#1259)
* Implement graceful shutdown for recording importer on SIGTERM/SIGINT * scalelite-recording-importer: implement stop timeout and exec stop command in systemd service file
1 parent 3ca4dc8 commit 4d4718f

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

lib/tasks/recordings.rake

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,26 @@ namespace :recordings do
1010
# Setup AWS S3 Client if enabled (auto looks up the env variables it needs)
1111
client = Aws::S3::Client.new if ENV['S3_RECORDING']
1212

13+
# On SIGTERM/SIGINT only set a flag; the in-progress import is allowed to
14+
# finish before the loop exits, so a running extraction is never interrupted.
15+
shutdown = false
16+
%w[TERM INT].each do |sig|
17+
Signal.trap(sig) { shutdown = true }
18+
end
19+
1320
loop do
1421
Dir.glob("#{dir}/*.tar").each do |file|
22+
break if shutdown
1523
Rails.logger.debug { "Found #{file}" }
1624
RecordingImporter.import(file, client)
1725
rescue StandardError => e
1826
Rails.logger.error("Failed to import recording: #{e}")
1927
sleep(args.latency.to_f)
2028
end
29+
break if shutdown
2130
sleep(args.latency.to_f)
2231
end
23-
rescue SignalException => e
24-
Rails.logger.info("Exiting recording importer on signal: #{e}")
32+
Rails.logger.info('Exiting recording importer gracefully')
2533
end
2634

2735
desc 'Search through the recordings and move unpublished recordings to the correct folder'

systemd/scalelite-recording-importer.service

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ After=scalelite-api.service
88
After=remote-fs.target
99
[Service]
1010
EnvironmentFile=/etc/default/scalelite
11+
TimeoutStopSec=140
1112
ExecStartPre=-/usr/bin/docker kill scalelite-recording-importer
1213
ExecStartPre=-/usr/bin/docker rm scalelite-recording-importer
1314
ExecStartPre=/usr/bin/docker pull blindsidenetwks/scalelite:${SCALELITE_TAG}-recording-importer
14-
ExecStart=/usr/bin/docker run --log-opt max-size=10m --log-opt max-file=5 --name scalelite-recording-importer --env-file /etc/default/scalelite --network scalelite --mount type=bind,source=${SCALELITE_RECORDING_DIR},target=/var/bigbluebutton blindsidenetwks/scalelite:${SCALELITE_TAG}-recording-importer
15+
ExecStart=/usr/bin/docker run --log-opt max-size=10m --log-opt max-file=5 --stop-timeout=120 --name scalelite-recording-importer --env-file /etc/default/scalelite --network scalelite --mount type=bind,source=${SCALELITE_RECORDING_DIR},target=/var/bigbluebutton blindsidenetwks/scalelite:${SCALELITE_TAG}-recording-importer
16+
ExecStop=/usr/bin/docker stop scalelite-recording-importer
1517
ExecStartPost=/usr/bin/docker image prune -f
1618
[Install]
1719
WantedBy=scalelite.target

0 commit comments

Comments
 (0)