A Ruby gem to create service checker for Themis Finals attack-defence CTF checking system.
gem install themis-checker-server
or just add gem 'themis-checker-server'
to your Gemfile and run bundle
.
A service checker should subclass Themis::Checker::Server
and override two methods.
Here's an example:
require 'themis/checker/server'
require 'themis/checker/result'
class SampleChecker < Themis::Checker::Server
def push(endpoint, flag, adjunct, metadata)
# business logic...
return Themis::Checker::Result::UP, adjunct
end
def pull(endpoint, flag, adjunct, metadata)
# business logic...
Themis::Checker::Result::UP
end
end
checker = SampleChecker.new
checker.run
Several environment variables should be specified to run service checker process:
A connection string for Beanstalk server.
A Beanstalk tube to listen to commands from Themis Finals
server.
A Beanstalk tube to report operation results to Themis Finals
server.
An optional service checker log level. One of DEBUG
, INFO
, WARN
, ERROR
, FATAL
or UNKNOWN
. Default is INFO
.
An optional parameter controlling $stdout.sync
.
There is a class member logger
. You can use it in overriden push
and pull
methods as @logger
.
Service checker process stops on INT
signal.
Configuration for God process manager
(0...2).to_a.each do |num|
God.watch do |w|
w.group = 'SERVICE_ALIAS'
w.name = "SERVICE_ALIAS-#{num}"
w.dir = '/path/to/checker'
w.uid = 'nobody'
w.gid = 'nogroup'
w.log = "/path/to/checker/logs/checker-#{num}.log"
w.start = 'bundle exec ruby checker.rb'
w.env = {
'BEANSTALKD_URI' => '127.0.0.1:11300',
'LOG_LEVEL' => 'INFO',
'STDOUT_SYNC' => 'true',
'TUBE_LISTEN' => 'themis.finals.service.SERVICE_ALIAS.listen',
'TUBE_REPORT' => 'themis.finals.service.SERVICE_ALIAS.report'
}
w.stop_signal = 'INT'
w.keepalive
end
end
Configuration for Supervisor process manager
[program:themis.finals.service.SERVICE_ALIAS.checker]
command=/opt/rbenv/shims/bundle exec ruby checker.rb
process_name=checker-%(process_num)s
numprocs=2
numprocs_start=0
priority=300
autostart=false
autorestart=true
startsecs=1
startretries=3
exitcodes=0,2
stopsignal=INT
stopwaitsecs=10
stopasgroup=false
killasgroup=false
user=nobody
redirect_stderr=false
stdout_logfile=/path/to/checker/logs/checker-%(process_num)s-stdout.log
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=10
stdout_capture_maxbytes=0
stdout_events_enabled=false
stderr_logfile=/path/to/checker/logs/checker-%(process_num)s-stderr.log
stderr_logfile_maxbytes=10MB
stderr_logfile_backups=10
stderr_capture_maxbytes=0
stderr_events_enabled=false
environment=APP_INSTANCE="%(process_num)s",BEANSTALKD_URI="127.0.0.1:11300",LOG_LEVEL="DEBUG",STDOUT_SYNC="true",TUBE_LISTEN="themis.finals.service.SERVICE_ALIAS.listen",TUBE_REPORT="themis.finals.service.SERVICE_ALIAS.report"
directory=/path/to/checker
serverurl=AUTO
[group:themis.finals.service.SERVICE_ALIAS]
programs=themis.finals.service.SERVICE_ALIAS.checker
MIT @ Alexander Pyatkin