Let c-treeACE Phone Home for Help
A frequent request we hear from administrators is an ability to be notified upon certain events from the server. One of the most important events is to know when the c-treeACE process has halted. Consider the case when a disk volume runs out of space and the server must come down to protect data integrity. For continuous operations, it is important for an administrator to be actively notified and take action.
c-treeACE has two configuration options available to execute specified actions upon server startup and shutdown:
SIGNAL_READY <executable script>
SIGNAL_DOWN <executable script>
Consider using these keywords for tasks that need to be completed once c-treeACE is up and running, or after c-treeACE shuts down.
A useful application of the SIGNAL_DOWN keyword is to send a notification, for example via email or SMS message to a text pager, should you want to know if your server is no longer active. As the SIGNAL_DOWN keyword is called even in the event of an abnormal server termination, it is a great way for c-treeACE to attempt to call out for assistance.
The following example is a simple script to notify a c-treeACE Administrator of a server shutdown event. It also attempts to restart the server, and to avoid an infinite retry loop, configured to only try three restart attempts before aborting. The SIGNAL_READY keyword is used to clear the restarts file on a successful restart.
This is only a brief example of what can be done. Other uses could include kicking off application scripts on server startup, and system maintenance routines on server shutdown.
Example Configuration
You will need to add the configuration keywords as in the following server configuration example.
ctsrvr_signals.cfg
; Server Name
SERVER_NAME FAIRCOMS
; Include these configuration options to execute any
; external scripts SIGNAL_DOWN signal_down.sh
SIGNAL_READY signal_ready.sh
; Location for data Files and Logs
LOCAL_DIRECTORY ./data/
; Create temporary files in the LOCAL_DIRECTORY directory
TMPNAME_PATH
; Communication protocols
COMM_PROTOCOL F_TCPIP
COMM_PROTOCOL FSHAREMM
; Data and index cache size
DAT_MEMORY 100 MB
IDX_MEMORY 100 MB
; Maximum number of c-tree files
FILES 1024
; Shutdown menu option does not prompt for administrator password
CONSOLE NO_SHUTDOWN_PROMPT
; Create a system tray icon for the database engine
CONSOLE TOOL_TRAY
; Restrict the database process to running on the specified CPUs
;CPU_AFFINITY 0,1
; Optimized transaction log writing
COMPATIBILITY LOG_WRITETHRU
LOG_SPACE 120 MB
CHECKPOINT_INTERVAL 10 MB
TRANSACTION_FLUSH 10000
CHECKPOINT_FLUSH 17
COMMIT_DELAY 2
LOG_TEMPLATE 2
Example Scripts
The following Linux Bash scripts assume a properly configured sendmail process on your environment. These can be readily tailored for nearly any platform, however. Always be mindful of appropriate security measures when taking actions such as these with proper permissions and such.
Note: The executable scripts must be located in the same directory as the server executable.
signal_down.sh
#!/bin/bash
# ==========================================
emailfile=email.txt
admin_email=administrator@mycompany.com
process_name=PROD01
process_email=PROD01
process_domain=localhost
restartfile=restarts.txt
restarts=0
# ==========================================
# Check if we have been attempting restarts
if [ -e $restartfile ] ; then
restarts=`cat $restartfile`
(( restarts++ ))
echo $restarts > $restartfile
else
restarts=1
echo $restarts > $restartfile
fi
# Setup the email header
datestring=`date`
echo To: $admin_email > "$emailfile"
echo From: "c-treeACE process $process_name"\<$process_email@$process_domain\> >> "$emailfile"
echo Subject: c-treeACE Notification for $process_name -- "$datestring" >> "$emailfile"
echo =========================================== >> "$emailfile"
echo c-treeACE Server shutdown detected: >> "$emailfile"
echo "$datestring" >> "$emailfile"
echo =========================================== >> "$emailfile"
echo >> "$emailfile"
echo This notification has been sent as a result of a SIGNAL_DOWN event >> "$emailfile"
echo from a c-treeACE Server shutdown. >> "$emailfile"
echo Please check for messages in the CTSTATUS.FCS log. >> "$emailfile"
echo >> "$emailfile"
echo >> "$emailfile"
echo =========================================== >> "$emailfile"
echo tail of CTSTATUS.FCS log >> "$emailfile"
echo =========================================== >> "$emailfile"
echo >> "$emailfile"
tail -n 20 CTSTATUS.FCS >> "$emailfile"
echo >> "$emailfile"
echo >> "$emailfile"
echo =========================================== >> "$emailfile"
echo tail of nohup log >> "$emailfile"
echo =========================================== >> "$emailfile"
echo >> "$emailfile"
tail -n 20 ctsrvr.log >> "$emailfile"
echo >> "$emailfile"
echo >> "$emailfile"
echo =========================================== >> "$emailfile"
# Restart the server if possible
echo Attempting to restart c-treeACE >> "$emailfile"
echo Attempt number: "$restarts" >> "$emailfile"
if [ $restarts -lt 3 ] ; then
nohup ./ctsrvr 1> ctsrvr.log 2> ctsrvr.log &
else
echo ABORTING... More than 3 server restart attempts >> "$emailfile"
fi
echo =========================================== >> "$emailfile"
echo >> "$emailfile"
echo >> "$emailfile"
echo =========================================== >> "$emailfile"
echo End of Message >> "$emailfile"
echo =========================================== >> "$emailfile"
sendmail -t < "$emailfile"
signal_ready.sh
#!/bin/bash
rm restarts.txt
#end of file
|