Jan 102011
While installing and configuring Wuala to start automatically on my headless server, I figured out I can use the same mechanism for PS3 Media Server (AKA PMS). So here the init.d script for PMS:
#!/bin/bash
### BEGIN INIT INFO
# Provides: pms
# Required-Start: $network $local_fs
# Required-Stop: $network $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start pms headless
### END INIT INFO
PMSUSER=pmsuser
PMSDIR=/home/pmsuser/pms
BACKPWD=`pwd`
case "${1:-''}" in
'start')
# start commands here
echo "Starting PMS..."
cd $PMSDIR
su $PMSUSER -c "screen -d -m $PMSDIR/PMS.sh"
;;
'stop')
# stop commands here
echo "Stopping PMS..."
p=`ps -ef | grep java | grep pmsuser | grep pms | awk '{print $2}'`
if [[ "$p" = "" ]] ; then
echo "PMS not running"
else
kill $p
fi
;;
'restart')
# restart commands here
$SELF stop
sleep 5
$SELF start
;;
'status')
# status commands here
p=`ps -ef | grep java | grep pmsuser | grep pms | awk '{print $2}'`
if [[ "$p" = "" ]] ; then
echo "PMS not running"
else
echo "PMS running with PID $p"
fi
;;
*)
# no parameter specified
echo "Usage: $SELF start|stop|restart|status"
exit 1
;;
esac
cd $BACKPWD