File otrs.init of Package otrs.8833
#!/bin/sh
#
# Copyright (c) 2012 Scorpio IT, Deidesheim, Germany
# All rights reserved
#
# Author: Christian Wittmer <rpm@scorpio-it.net>
#
# /etc/init.d/otrs
# and its symbolic link
# /(usr/)sbin/rcotrs
#
### BEGIN INIT INFO
# Provides: otrs
# Required-Start: apache2
# Should-Start: mysql postgresql otrs-scheduler
# Required-Stop: apache2
# Should-Stop: mysql postgresql otrs-scheduler
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: start OTRS
# Description: start OTRS (Open Ticket Request System)
### END INIT INFO
export LANG=POSIX
PATH="/bin:/usr/bin:/sbin:/usr/sbin"
# Check for existence of needed config file and read it
OTRS_SYSCONFIG=/etc/sysconfig/otrs
test -r $OTRS_SYSCONFIG || { echo "$OTRS_SYSCONFIG not existing";
if [ "$1" = "stop" ]; then exit 0;
else exit 6; fi; }
# Read config
. $OTRS_SYSCONFIG
if [ -z $OTRS_ROOT ]; then
echo "OTRS_ROOT not set";
echo "check config: $OTRS_SYSCONFIG";
exit 6;
fi
if [ -z $OTRS_POSTMASTER ]; then
echo "OTRS_POSTMASTER not set";
echo "check config: $OTRS_SYSCONFIG";
exit 6;
fi
if [ -z $OTRS_CHECKDB ]; then
echo "OTRS_CHECKDB not set";
echo "check config: $OTRS_SYSCONFIG";
exit 6;
fi
if [ -z $OTRS_CLEANUP ]; then
echo "OTRS_CLEANUP not set";
echo "check config: $OTRS_SYSCONFIG";
exit 6;
fi
if [ -z $OTRS_SPOOLDIR ]; then
echo "OTRS_SPOOLDIR not set";
echo "check config: $OTRS_SYSCONFIG";
exit 6;
fi
# Shell functions sourced from /etc/rc.status:
# rc_check check and set local and overall rc status
# rc_status check and set local and overall rc status
# rc_status -v ditto but be verbose in local rc status
# rc_status -v -r ditto and clear the local rc status
# rc_failed set local and overall rc status to failed
# rc_failed <num> set local and overall rc status to <num>
# rc_reset clear local rc status (overall remains)
# rc_exit exit appropriate to overall rc status
. /etc/rc.status
# Reset status of this service
rc_reset
# Return values acc. to LSB for all commands but status:
# 0 - success
# 1 - generic or unspecified error
# 2 - invalid or excess argument(s)
# 3 - unimplemented feature (e.g. "reload")
# 4 - user had insufficient privileges
# 5 - program is not installed
# 6 - program is not configured
# 7 - program is not running
# 8--199 - reserved (8--99 LSB, 100--149 distrib, 150--199 appl)
case "$1" in
# ------------------------------------------------------
# start
# ------------------------------------------------------
start)
echo "Starting $OTRS_PROG"
# --
# start web server
# --
if test $OTRS_HTTP_RUNNING -gt 0; then
if $OTRS_USED_WEBSERVER_RCSCRIPT status > /dev/null 2>&1 ; then
echo " Checking $OTRS_USED_WEBSERVER ... done."
rc_status
else
echo " Checking $OTRS_USED_WEBSERVER ... failed!"
echo " --> Please start the web server first! ($OTRS_USED_WEBSERVER_RCSCRIPT start) <--"
rc_failed
exit 1
fi
else
echo " Disabled: web server check!"
fi
# --
# check database
# --
if test $OTRS_DB_RUNNING -gt 0; then
if $OTRS_USED_DB_RCSCRIPT status > /dev/null 2>&1 ; then
echo " Checking $OTRS_USED_DB ... done."
rc_status
else
echo " Checking $OTRS_USED_DB ... failed."
echo " --> Please start the database at first! ($OTRS_USED_DB_RCSCRIPT start) <--"
rc_failed
rc_status -v
exit 1;
fi
else
echo " Disabled: database check!"
fi
# --
# database connect
# --
echo -n " Checking database connection... ("
if ! $OTRS_CHECKDB -s 1; then
echo ") "
echo "----------------------------------------------------------------------------"
echo " Error: Maybe your database isn't configured yet? "
echo "----------------------------------------------------------------------------"
echo ""
echo ""
echo " Try the web installer to configure your database: "
echo ""
echo ""
echo " -->> http://$OTRS_HOST/$OTRS_HTTP_LOCATION/installer.pl <<-- "
echo ""
echo ""
echo "----------------------------------------------------------------------------"
echo " or configure your database with README.database (DB - Setup Example) "
echo "----------------------------------------------------------------------------"
rc_failed
rc_status -v
exit 1;
else
echo ")."
rc_status
fi
# --
# OTRS Scheduler Service
# --
if test $OTRS_SCHEDULER_RUNNING -gt 0; then
if $OTRS_USED_SCHEDULER_RCSCRIPT status > /dev/null 2>&1 ; then
echo " Checking OTRS SCHEDULER ... done."
rc_status
else
echo " Checking OTRS SCHEDULER ... failed!"
#echo " --> Please start the scheduler first! ($OTRS_USED_SCHEDULER_RCSCRIPT start) <--"
#rc_failed
#exit 1
/etc/init.d/otrs-scheduler $1
fi
else
echo " Disabled: scheduler check!"
fi
# --
# enable otrs.PostMaster.pl
# --
echo -n " Enable $OTRS_POSTMASTER ..."
if chmod 755 $OTRS_POSTMASTER; then
echo " done."
rc_status
else
echo " failed."
fi
# --
# check otrs spool dir
# --
echo -n " Checking otrs spool dir... "
for i in $OTRS_SPOOLDIR/* ; do
# process old emails
if echo $i | grep -v '*' >> /dev/null; then
echo -n " Starting otrs PostMaster... ($i) "
if cat $i | $OTRS_POSTMASTER >> /dev/null 2>&1; then
rm $i && echo "(remove email)";
else
rc_failed
fi
fi
done
echo " done."
rc_status
# --
# start cron stuff
# --
if test $OTRS_CRON_RUNNING -gt 0; then
if mkdir -p $OTRS_CRON_DIR; cd $OTRS_CRON_DIR && ls *|grep -v '.dist'|grep -v '.save'|grep -v 'CVS'|grep -v '.rpm'|xargs cat > $OTRS_CRON_TMP_FILE && crontab $OTRS_CRON_USER $OTRS_CRON_TMP_FILE ; then
echo " Creating cronjobs (source $OTRS_CRON_DIR/*) ... done."
rc_status
else
echo " Creating cronjobs (source $OTRS_CRON_DIR/*) ... failed!"
rc_failed
exit 1
fi
else
echo " Disabled: cronjobs!"
fi
echo ""
echo " -->> http://$OTRS_HOST/$OTRS_HTTP_LOCATION/index.pl <<-- "
# show status
rc_status -v
;;
# ------------------------------------------------------
# stop
# ------------------------------------------------------
stop)
echo "Shutting down $OTRS_PROG "
# --
# disable otrs.PostMaster.pl
# --
echo -n " Disable $OTRS_POSTMASTER ..."
if chmod 644 $OTRS_POSTMASTER; then
echo " done."
rc_status
else
echo " failed."
fi
# --
# stop cron stuff
# --
if test $OTRS_CRON_RUNNING -gt 0; then
if type -a crontab 2&>/dev/null && crontab $OTRS_CRON_USER -r ; then
echo " Shutting down cronjobs ... done."
rc_status
else
echo " Shutting down cronjobs ... failed!"
rc_failed
exit 1
fi
else
echo " Disabled: cronjobs!"
fi
# --
# stop scheduler
# --
if test $OTRS_SCHEDULER_RUNNING -gt 0; then
echo -e " Shutting down OTRS scheduler ..."
$OTRS_SCHEDULER -a stop
echo " done."
fi
# show status
rc_status -v
;;
# ------------------------------------------------------
# start-force
# ------------------------------------------------------
start-force)
echo "Starting $OTRS_PROG (completely)"
# --
# start web server
# --
if test $OTRS_HTTP_RUNNING -gt 0; then
if $OTRS_USED_WEBSERVER_RCSCRIPT restart > /dev/null 2>&1 ; then
echo " Starting $OTRS_USED_WEBSERVER ... done."
rc_status
else
echo " Starting $OTRS_USED_WEBSERVER ... failed!"
rc_failed
exit 1
fi
else
echo " Disabled: web server check!"
fi
# --
# check database
# --
if test $OTRS_DB_RUNNING -gt 0; then
if $OTRS_USED_DB_RCSCRIPT restart > /dev/null 2>&1 ; then
# just in case, some databases can't get ready so fast!
sleep 5;
echo " Starting $OTRS_USED_DB ... done."
rc_status
else
echo " Starting $OTRS_USED_DB ... failed."
rc_failed
rc_status -v
exit 1;
fi
else
echo " Disabled: database check!"
fi
# --
# start normal
# --
$0 start
# show status
rc_status -v
;;
# ------------------------------------------------------
# stop-force
# ------------------------------------------------------
stop-force)
# --
# stop normal
# --
$0 stop
# --
# clean up
# --
if test $OTRS_CLEANUP; then
if $OTRS_CLEANUP > /dev/null 2>&1 ; then
echo " Cleaning up session and log cache ... done."
else
echo " Cleaning up session and log cache ... failed."
fi
fi
# --
# stop force
# --
echo "Shutting down $OTRS_PROG (completely)"
# --
# webserver
# --
if test $OTRS_HTTP_RUNNING -gt 0; then
if $OTRS_USED_WEBSERVER_RCSCRIPT stop > /dev/null 2>&1 ; then
echo " Shutting down $OTRS_USED_WEBSERVER ... done."
rc_status
else
echo " Shutting down $OTRS_USED_WEBSERVER ... failed."
rc_failed
fi
fi
# --
# database
# --
if test $OTRS_DB_RUNNING -gt 0; then
if $OTRS_USED_DB_RCSCRIPT stop > /dev/null 2>&1 ; then
echo " Shutting down $OTRS_USED_DB ... done."
rc_status
else
echo " Shutting down $OTRS_USED_DB ... failed."
rc_failed
fi
fi
# show status
rc_status -v
;;
# ------------------------------------------------------
# restart
# ------------------------------------------------------
restart)
$0 stop
$0 start
# Remember status and be quiet
rc_status
;;
# ------------------------------------------------------
# restart-force
# ------------------------------------------------------
restart-force)
$0 stop-force && sleep 3
$0 start-force
# Remember status and be quiet
rc_status
;;
# ------------------------------------------------------
# try-restart
# ------------------------------------------------------
try-restart|condrestart)
if test "$1" = "condrestart"; then
echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
fi
$0 status
if test $? = 0; then
$0 restart
else
# Not running is not a failure.
rc_reset
fi
# Remember status and be quiet
rc_status
;;
# ------------------------------------------------------
# reload
# ------------------------------------------------------
reload)
## OTRS does not support reload:
rc_failed 3
# Remember status and be verbose
rc_status -v
;;
# ------------------------------------------------------
# cleanup
# ------------------------------------------------------
cleanup)
# --
# check otrs spool dir
# --
echo -n " Checking otrs spool dir... "
for i in $OTRS_SPOOLDIR/* ; do
# process old emails
echo $i | grep -v '*' >> /dev/null && \
echo "" && \
echo -n " Starting otrs PostMaster... ($i) " && \
cat $i | $OTRS_POSTMASTER >> /dev/null 2>&1 && \
echo -n "remove email... " && \
(rm $i || rc_failed)
done
echo " done."
rc_status
# Remember status and be quiet
rc_status
;;
# ------------------------------------------------------
# status
# ------------------------------------------------------
status)
# --
# web server
# --
$OTRS_USED_WEBSERVER_RCSCRIPT status
# --
# database
# --
$OTRS_USED_DB_RCSCRIPT status
# --
# db check
# --
echo -n "Checking database connection... ("
if ! $OTRS_CHECKDB -s 1; then
echo ") "
echo "----------------------------------------------------------------------------"
echo " Error: Maybe your database isn't configured yet? "
echo "----------------------------------------------------------------------------"
else
echo ")."
fi
# --
# scheduler check
# --
$OTRS_USED_SCHEDULER_RCSCRIPT status
# --
# postmaster check
# --
echo -n "Checking $OTRS_POSTMASTER ... "
if test -x $OTRS_POSTMASTER; then
echo "(active) done."
else
echo "(not active) failed."
fi
# --
# spool dir
# --
echo -n "Checking otrs spool dir... "
for i in $OTRS_SPOOLDIR/* ; do
# echo old emails
echo $i | grep -v '*' > /dev/null && \
echo "" && \
echo -n " (message:$i) found! "
done
echo "done."
;;
*)
echo "Usage: $0 {start|stop|stop-force|start-force|status|restart|restart-force|cleanup}"
exit 1
esac
# Inform the caller not only verbosely and set an exit status.
rc_exit