Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am using Ubuntu and found this init.d script for LibreOffice headless.

Problem is that it does not seem to be stopping the process when asked to "stop". Any help greatly appreciated.

Two other questions: I have seen the command start-stop-daemon used in other init.d scripts - what is the advantage to that over the approach used in this script? Also, I want to be able to run this script as an unprivileged users, but it says it cannot create the PID file. What's the "right" way to allow unprivileged users to run this script?

Thanks!

#!/bin/bash
# libreoffice.org  headless server script
#
# chkconfig: 2345 80 30
# description: headless libreoffice server script
# processname: libreoffice
# 
# Author: Vic Vijayakumar
# Modified by Federico Ch. Tomasczik
# Modified by Manuel Vega Ulloa
OOo_HOME=/usr/bin
SOFFICE_PATH=$OOo_HOME/soffice
PIDFILE=/var/run/libreoffice-server.pid
set -e
case "$1" in
    start)
    if [ -f $PIDFILE ]; then
      echo "LibreOffice headless server has already started."
      sleep 5
      exit
    fi
      echo "Starting LibreOffice headless server"
      $SOFFICE_PATH --headless --nologo --nofirststartwizard --accept="socket,host=127.0.0.1,port=2002;urp" & > /dev/null 2>&1
      touch $PIDFILE
    ;;
    stop)
    if [ -f $PIDFILE ]; then
      echo "Stopping LibreOffice headless server."
      #killall -9 soffice 
      #killall -9 soffice.bin
      killall -9 oosplash
      #start-stop-daemon --stop --signal HUP --quiet --pidfile $PIDFILE  --exec $DAEMON || true

      rm -f $PIDFILE
      exit
    fi
      echo "LibreOffice headless server is not running."
      exit
    ;;
    *)
    echo "Usage: $0 {start|stop}"
    exit 1
esac
exit 0
share|improve this question

1 Answer 1

up vote 1 down vote accepted

You should use PID and PIDFILE in the right way. For example (exerpt from my working script):

case "$1" in
    start)
    if [ -f $PIDFILE ]; then
      echo "LibreOffice headless server has already started."
      sleep 5
      exit
    fi
      echo "Starting LibreOffice headless server"
      $SOFFICE_PATH --headless --nologo --nofirststartwizard --    accept="socket,host=127.0.0.1,port=2002;urp" & > /dev/null 2>&1
      PID=`ps ax|grep "soffice.bin --headless"|grep -v grep|cut -d \  -f 1`
      echo $PID> $PIDFILE
    ;;
    stop)
    if [ -f $PIDFILE ]; then
      echo "Stopping LibreOffice headless server."
      kill `cat $PIDFILE`
      rm -f $PIDFILE
      exit
    fi
      echo "LibreOffice headless server is not running."
      exit
    ;;
    *)
    echo "Usage: $0 {start|stop}"
    exit 1
esac
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.