Skip to content

Commit

Permalink
Added a maintenance service
Browse files Browse the repository at this point in the history
  • Loading branch information
wonka committed Mar 26, 2012
1 parent d24464e commit aee95b4
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 3 deletions.
118 changes: 118 additions & 0 deletions glass_maintenance
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#!/bin/bash

if [ -s $GEMSTONE/seaside/etc/gemstone.secret ]; then
. $GEMSTONE/seaside/etc/gemstone.secret
else
echo 'Missing password file $GEMSTONE/seaside/etc/gemstone.secret'
exit 1
fi

# Requires the gemstone name as a parameter
if [ "a$1" = "a" ]; then
echo 'Missing argument <gemstone name>'
exit 1
fi

GEMSTONE_NAME=$1
echo "GEMSTONE_NAME is $GEMSTONE_NAME"

# Make sure the environment is sane before we start up
if [ -z $LANG ]; then echo "LANG is not set, bailing out"; exit 3; fi
if [ -z $GEMSTONE_NAME ]; then echo "GEMSTONE_NAME is not set, bailing out"; exit 3; fi

exec $GEMSTONE/bin/topaz -l -T300000 << EOF
set user DataCurator pass $GEMSTONE_CURATOR_PASS gems $1
display oops
iferror where
login
run
"record gems pid in the pid file"
| file |
(GsFile isServerDirectory: '$GEMSTONE_DATADIR') ifFalse: [ ^nil ].
file := GsFile openWriteOnServer: '$GEMSTONE_DATADIR/${1}_maintenance_gem.pid'.
file nextPutAll: (System gemVersionReport at: 'processId') printString.
file cr.
file close.
(ObjectLogEntry
info: 'MTCE: startup'
object: 'pid: ', (System gemVersionReport at: 'processId') printString) addToLog.
System commitTransaction
ifFalse: [
System abortTransaction.
nil error: 'Could not commit ObjectLog entry' ].
%
run
| count |
true "enable for remote breakpoints and profiling"
ifTrue: [
GemToGemAnnouncement installStaticHandler.
Exception
installStaticException:
[:ex :cat :num :args |
BreakpointNotification signal.
"needed to avoid infinite loop when resuming from a breakpoint"
ex _incrementBreakpointsToIgnore. ]
category: GemStoneError
number: 6005 "#rtErrCodeBreakpoint"
subtype: nil.
System commitTransaction ifFalse: [ nil error: 'Could not commit for GemToGemSignaling' ]].
System transactionMode: #manualBegin.
Exception
installStaticException:
[:ex :cat :num :args |
"Run the abort in a lowPriority process, since we must acquire the
transactionMutex."
[
GRPlatform current transactionMutex
critical: [
GRPlatform current doAbortTransaction ].
System enableSignaledAbortError.
] forkAt: Processor lowestPriority.
]
category: GemStoneError
number: 6009 "#rtErrSignalAbort"
subtype: nil.
System enableSignaledAbortError.
"This thread is needed to handle the SigAbort exception, when the primary
thread is blocked. Assuming default 60 second STN_GEM_ABORT_TIMEOUT, wake
up at 30 second intervals."
[
[ true ] whileTrue: [ (Delay forSeconds: 30) wait ].
] forkAt: Processor lowestPriority.
count := 0.
[true] whileTrue: [ [
"run maintenance tasks"
WAGemStoneMaintenanceTask performTasks: count.
"Sleep for a minute"
(Delay forSeconds: 60) wait.
count := count + 1]
on: Error, Halt, BreakpointNotification
do: [:ex |
System inTransaction
ifTrue: [
DebuggerLogEntry createContinuationLabeled: 'MTCE continuation'.
System commitTransaction.
System beginTransaction ]
ifFalse: [
System beginTransaction.
DebuggerLogEntry createContinuationLabeled: 'MTCE continuation'.
System commitTransaction].
ex isResumable ifTrue: [ex resume]]].
%
run
GemToGemAnnouncement uninstallStaticHandler.
System beginTransaction.
(ObjectLogEntry
fatal: 'MTCE: topaz exit'
object:
'pid: ', (System gemVersionReport at: 'processId') printString) addToLog.
System commitTransaction.
%
EOF
40 changes: 37 additions & 3 deletions glass_stone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,31 @@ def hyper_service_file
File.join(@@gemstone_scripts_directory, 'run_hyper_service')
end

def maintenance_service_file
File.join(@@gemstone_scripts_directory, 'run_maintenance_service')
end

def maintenance_service
"#{name}-maint"
end
def create_daemontools_structure
create_maintenance_daemontools_structure
services_names.each do |service_name|
create_daemontools_structure_for(service_name, hyper_service_file)
end
end

def create_daemontools_structure_for(service_name, run_file)
service_directory = "/service/#{service_name}"
fail "Service directory #{service_directory} exists, please remove it manually, ensuring all services are stopped" if File.exists? service_directory
mkdir_p "#{service_directory}/log"
system("cd #{service_skeleton_template}; find -path .git -prune -o -print | cpio -p #{service_directory}")
system("ln -s #{hyper_service_file} #{service_directory}/run")
system("ln -s #{run_file} #{service_directory}/run")
touch "#{service_directory}/down"
end
end

def create_maintenance_daemontools_structure
create_daemontools_structure_for(maintenance_service, maintenance_service_file)
end

def remove_daemontools_structure
Expand All @@ -59,8 +75,26 @@ def remove_daemontools_structure
def start_hypers
GlassStone.clear_status
services_names.each { |service_name|
start_service_named(service_name) }
end

def start_maintenance
GlassStone.clear_status
start_service_named(maintenance_service)
end

def start_service_named(a_service_name)
option = if name == 'development' then 'o' else 'u' end
system("svc -#{option} /service/#{service_name}") }
system("svc -#{option} /service/#{a_service_name}")
end

def start_maintenance_fg
raise 'Environment variable LANG not set, you are probably running this from a restricted shell - bailing out' if not ENV['LANG']
exec(glass_maintenance_command)
end

def glass_maintenance_command
"exec #{@@gemstone_scripts_directory}/glass_maintenance '#{name}'"
end

def start_hyper_fg(port)
Expand Down
15 changes: 15 additions & 0 deletions run_maintenance_service
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/ruby

my_path = File.expand_path(__FILE__)
puts "My path #{my_path}"
require "#{File.dirname(File.readlink(my_path))}/glass_stone"
service_name = File.dirname(my_path).split("/").last
service_name =~ /([A-Za-z\.\-]*)-maint/
stone_name = $1
port = $2

ENV['LANG'] = 'en_ZA.UTF-8'

puts "Starting up a maintenance gem for #{stone_name}"
stone = GlassStone.new(stone_name)
stone.start_maintenance_fg

0 comments on commit aee95b4

Please sign in to comment.