diff --git a/service_files/README b/service_files/README new file mode 100644 index 00000000..924168ce --- /dev/null +++ b/service_files/README @@ -0,0 +1,20 @@ +Installing DataBus as a system service + +M. Hopcroft, Sep2013 + hopcroft@hp.com + + +DataBus is an open-source database management system. It is typically used with cassandra to manage building management data. +This file describes a method of using DataBus as a "System V"-style system service on Ubuntu GNU/Linux. There are many possible configurations of a system service, and you should be prepared to modify the files here to suit your needs. + +After the service files are installed, you can manage DataBus with system service commands start,stop,status,restart. For example: + + $ service databus status + Wed Oct 2 12:48:06 PDT 2013 | 1 DataBus processes are running + * DataBus webapp is running + $ + + +To install, run the script "databus_service_install.sh" as root (sudo) to create the necessary folders and files. This script assumes that DataBus is installed at /opt/databus, and that cassandra is already installed on the same system. This script will only add files to your system and DataBus installation, and will not otherwise modify the DataBus files. + + diff --git a/service_files/databus b/service_files/databus new file mode 100755 index 00000000..f5d9285a --- /dev/null +++ b/service_files/databus @@ -0,0 +1,98 @@ +### BEGIN INIT INFO +# Provides: databus +# Required-Start: cassandra networking +# Required-Stop: +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: DataBus (cassandra management and I/O) +# Description: The DataBus application provides web-based access to a cassandra data store. +### END INIT INFO + +# This script written by M. Hopcroft, Sep2013 +# hopcroft@hp.com + + +# Using the lsb functions to perform the operations. +. /lib/lsb/init-functions + +# Process name (for display) +NAME=DataBus + +# Daemon name (the executable for this service) +# Note: you must set the value for the pid file to be the same as in the +# DataBus startup script) +DAEMON=/opt/databus/webapp/startService.sh + +# pid file for the system service (note: you must create this directory) +PIDFILE=/var/run/databus/databus.pid +if [ ! -d /var/run/databus ]; then + echo "Cannot create pid file in \"/var/run/databus\". Cannot start." + exit 6 +fi + +# Switch for the service commands +case "$1" in + start) + if [ ! -e $PIDFILE ]; then + # If the daemon is not there, then exit. + if [ ! -x $DAEMON ]; then + echo "Cannot execute \"$DAEMON\"" + exit 5 + fi + log_daemon_msg "Starting $NAME" + # Start the daemon using start-stop-daemon + start-stop-daemon --start --verbose --pidfile $PIDFILE --exec $DAEMON + # it takes a few seconds to start up + echo "[Expect a delay of 10 seconds or so before web services start]" + sleep 10 + log_success_msg "Started $NAME" + else + isRunning=`pgrep -cf /opt/databus` + echo "$NAME is already running ($isRunning) or the pid file is invalid" + log_failure_msg "Cannot start $NAME" + fi + ;; + + stop) + if [ -e $PIDFILE ]; then + status_of_proc -p $PIDFILE $DAEMON "$NAME webapp" && status="0" || status="$?" + if [ "$status" = 0 ]; then + echo " Stopping $NAME webapp..." + start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE + /bin/rm -rf $PIDFILE + log_success_msg "$NAME stopped." + fi + else + log_daemon_msg "$NAME webapp is not running" + exit 1 + fi + ;; + + restart) + echo "Restarting " $0 + $0 stop + echo "pause to ensure DataBus has terminated (5s)" + sleep 5s + $0 start + ;; + + status) + #myIP=`ifconfig eth0 | sed -rn 's/.*r:([^ ]+) .*/\1/p'` + # Check the status of the process + isRunning=`pgrep -cf /opt/databus` + if [ -e $PIDFILE ]; then + if [ $isRunning -ge 1 ]; then + echo "`date` | $isRunning $NAME processes are running" + fi + status_of_proc -p $PIDFILE $DAEMON "$NAME webapp" && exit 0 || exit $? + else + log_daemon_msg "$NAME webapp is not running" + fi + ;; + + *) + # For invalid arguments, print the usage message. + echo "Usage: $0 {start|stop|restart|status}" + exit 2 + ;; +esac diff --git a/service_files/install_service.sh b/service_files/install_service.sh new file mode 100755 index 00000000..37183b8c --- /dev/null +++ b/service_files/install_service.sh @@ -0,0 +1,53 @@ +#!/bin/sh +# Install files and directories for using DataBus as a system service +# run as sudo +# +# M. Hopcroft, hopcroft@hp.com +# + +echo " " +echo "This script will create directories and copy files for using DataBus as a system service." + +# Location of the DataBus web application files (play) +dbapproot=/opt/databus/webapp + +user=`whoami` +origuser=`logname` + +if [ $user != "root" ]; then + echo " " + echo " ERROR: this script is designed to be run by root (sudo)" + echo " " + sleep 4 + exit 2 +fi + +cd $dbapproot +cd ../service_files +echo `pwd` + +# Make directories +echo " make directories..." +# pid file and log file +for newdir in /var/run/databus /var/log/databus +do + if [ ! -d $newdir ]; then + mkdir -vp $newdir + chmod a+rw $newdir + fi +done + +# Copy files +echo " copy files..." +# logfile configuration +cp -vfp service.logback.xml $dbapproot/conf +# service script +cp -vfp databus /etc/init.d/databus +chmod a+x /etc/init.d/databus +# service executable +cp -vfp startService.sh $dbapproot/startService.sh +chmod a+x $dbapproot/startService.sh + +echo " done." + + diff --git a/service_files/reset_data.sh b/service_files/reset_data.sh new file mode 100755 index 00000000..f79b75db --- /dev/null +++ b/service_files/reset_data.sh @@ -0,0 +1,43 @@ +#!/bin/sh +# Delete the cassandra data directories in order to reset a DataBus installation +# This will delete all data, user info, charts, etc from DataBus. +# run as sudo +# +# M. Hopcroft, hopcroft@hp.com +# + +currentdir=`pwd` + +user=`whoami` +if [ $user != "root" ]; then + echo " " + echo " ERROR: this script is designed to be run by root (sudo)" + echo " " + sleep 4 + exit 2 +fi + +echo "WARNING: This will wipe out all of the data in your DataBus installation" +echo "Cancel now with Ctrl-C if you do not want to do this..." +sleep 4 + +echo " Stopping DataBus:" +service databus stop +echo " Stopping Cassandra:" +service cassandra stop +echo "Deleting Cassandra database data..." +cd /var/lib/cassandra +for cass_dir in data commitlog +do + rm -vrf $cass_dir + mkdir -v $cass_dir + chown cassandra:cassandra $cass_dir + chmod 700 $cass_dir +done +echo " done." +service cassandra start +cd $currentdir +echo "Start DataBus when ready (service databus start)." +#service databus start + + diff --git a/service_files/service.logback.xml b/service_files/service.logback.xml new file mode 100755 index 00000000..fed175d7 --- /dev/null +++ b/service_files/service.logback.xml @@ -0,0 +1,47 @@ + + + + + + filter + true + INFO + DENY + + + + /var/log/databus/databus.log + + + databus.%i.log.zip + 1 + 10 + + + + 50MB + + + %date{ISO8601} [%X{txId}-%X{user}] [%thread] %logger{15} %method%n%-4level: %message%n + + + + + + + + + + + + + + + + + diff --git a/service_files/startService.sh b/service_files/startService.sh new file mode 100755 index 00000000..bea08bd4 --- /dev/null +++ b/service_files/startService.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# This script starts DataBus for production use as a background process. +# DataBus is developed using the play framework. +# The script starts the webapp using play in background mode. +# You must create the directories for the pid file (/var/run/databus/) and the +# log files (/var/log/databus/) before using this script. +# +# This script is compatible with the init.d-style system service script +# named "databus" +# +# M. Hopcroft, hopcroft@hp.com +# Sep2013 + +# Location of the DataBus web application files (play) +dbapproot=/opt/databus/webapp +# pid file for the system service +# Note: you must create this directory +# Note: this must be the same as the directory in the databus service script +PIDFILE=/var/run/databus/databus.pid + +# The logback file defines the logging parameters +# If using "service" logback file, you must create /var/log/databus/ +if [ -e $dbapproot/conf/service.logback.xml ]; then + cp $dbapproot/conf/service.logback.xml $dbapproot/conf/logback.xml +fi + +# Start the webapp +$dbapproot/play-1.2.5/play start $dbapproot --%prod --silent -Xmx1024M --pid_file=$PIDFILE +exit 0 + +# Debug options +#-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=1044