#!/bin/sh #==================================================================== # Start/stop script for LinShare server. # (http://www.linpki.org/projects/show/linshare). # # chkconfig: 2345 20 100 # description: LinShare # ### BEGIN INIT INFO # Provides: linshare # Required-Start: $syslog # Required-Stop: $syslog # Should-Start: $network $time # Should-Stop: $network $time # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: LinShare # Description: LinShare init script ### END INIT INFO # # Copyright (C) 2010 Thomas CHEMINEAU # Copyright (C) 2010 LINAGORA GROUP # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # GPL License: http://www.gnu.org/licenses/gpl.txt # #==================================================================== #==================================================================== # Changelog #==================================================================== # Version X (Date) # - What you have done # Author: Your Name # Author: Your Name # # Version 0.1 (03/2010) # - First version # Author: Thomas CHEMINEAU (LINAGORA GROUP) #==================================================================== # ----------------------------------------------------------------------------- # Parameters # ----------------------------------------------------------------------------- LINSHARE_HOME="/opt/linshare" LINSHARE_BIN="${LINSHARE_HOME}/linshare.sh" LINSHARE_BACKUPDIR="${LINSHARE_HOME}/var/backups" LINSHARE_JETTYDIR="/tmp" # ----------------------------------------------------------------------------- # Functions # ----------------------------------------------------------------------------- # # Do backup. # Works for: # - PostgreSQL under Debian. # backup () { ret=1 # Check backup directory if [ ! -d "${LINSHARE_BACKUPDIR}" ]; then mkdir -p "${LINSHARE_BACKUPDIR}" fi # Debian if [ -f /etc/debian_version ]; then # PostgreSQL if [ -n "`echo ${LINSHARE_DBDRIVER} | grep -i postgresql`" ]; then for database in ${LINSHARE_DBNAME}; do file="${LINSHARE_BACKUPDIR}/${database}-`date +%Y%m%d`.sql" su - postgres -c "pg_dump ${database}" > ${file} ret=$? if [ ${ret} -ne 0 ]; then break; fi done fi fi if [ ${ret} -eq 0 ]; then echo "OK" else echo "FAILED" fi exit ${ret} } # # Purge Jetty temporary files. # purge () { cmd="ls -1rt ${LINSHARE_JETTYDIR}/j[0-9]*" max="`${cmd} | wc -l`" nb="`expr ${max} - 2`" if [ `expr ${nb} \< 2` -eq 0 ]; then rm `${cmd} | head -n ${nb}` fi } # # Call LinShare script. # run () { ${LINSHARE_BIN} $* > /dev/null 2>&1 if [ $? -eq 0 ]; then echo "OK" else echo "FAILED" fi } # # Print status. Heartbeat compliant. # 0: RUNNING, 3:STOPPING # status () { ${LINSHARE_BIN} check > /dev/null 2>&1 if [ $? -eq 0 ]; then echo "OK" exit 0 else echo "KO" exit 3 fi } # ----------------------------------------------------------------------------- # Main # ----------------------------------------------------------------------------- ACTIONS="" case "$1" in "start") ACTIONS="start" ;; "stop") ACTIONS="stop" ;; "restart") ACTIONS="stop start" ;; "backup") ACTIONS="backup" ;; "purge") ACTIONS="purge" ;; "status") ACTIONS="status" ;; *) echo "`basename $0` {start|stop|restart|backup|status}" exit 2 ;; esac if [ -f /etc/default/`basename $0` ]; then . /etc/default/`basename $0`; fi for action in ${ACTIONS}; do case "${action}" in "start") echo -n "Starting LinShare... " run $* ;; "stop") echo -n "Stopping LinShare... " run $* ;; "backup") echo -n "Backup in progress... " backup ;; "purge") purge ;; "status") status ;; esac done