solotimes
12/3/2012 - 12:34 PM

Libreoffice LSB init script

Libreoffice LSB init script

#!/bin/sh
#
#  Startup Script for the LibreOffice server. Save it into /etc/init.d/libreoffice
#  and install it using `insserv /etc/init.d/libreoffice`.
#
#     Copyright (C) 2012 Marcello Barnaba <vjt@openssl.it>
#
# LSB compatible service control script; see http://www.linuxbase.org/spec/
#
### BEGIN INIT INFO
# Provides:          libreoffice
# Required-Start:    $syslog $remote_fs
# Should-Start:      $time
# Required-Stop:     $syslog $remote_fs
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: Libreoffice daemon
# Description:       Start the Libreoffice Server UNO Python interface
### END INIT INFO

# Check for missing binaries (stale symlinks should not happen)
# Note: Special treatment of stop for LSB conformance
OFFICE_BIN=/usr/lib/libreoffice/program/soffice.bin
test -x $OFFICE_BIN || { echo "$OFFICE_BIN not installed";
	if [ "$1" = "stop" ]; then exit 0;
	else exit 5; fi; }


OFFICE_USER="office"
OFFICE_ARGS="--headless --accept=socket,host=127.0.0.1,port=8100;urp;"

. /etc/rc.status

# Reset status of this service
rc_reset

case "$1" in
    start)
	echo -n "Starting LibreOffice server "
	/usr/bin/sudo -u $OFFICE_USER /sbin/startproc $OFFICE_BIN $OFFICE_ARGS

	# Remember status and be verbose
	rc_status -v
	;;
    stop)
	echo -n "Shutting down LibreOffice server "
	/usr/bin/sudo -u $OFFICE_USER /sbin/killproc $OFFICE_BIN

	rc_status -v
	;;
    try-restart|condrestart)
	## Do a restart only if the service was active before.
	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
		rc_reset	# Not running is not a failure.
	fi

	rc_status
	;;
    restart)
	## Stop the service and regardless of whether it was
	## running or not, start it again.
	$0 stop
	$0 start

	# Remember status and be quiet
	rc_status
	;;
    status)
	echo -n "Checking for LibreOffice server "
	/usr/bin/sudo -u $OFFICE_USER /sbin/checkproc $OFFICE_BIN

	rc_status -v
	;;
    *)
	echo "Usage: $0 {start|stop|status|try-restart|restart}"
	exit 1
	;;
esac
rc_exit