After finding this awesome application, i've installed it in my home media server, an openSUSE box. So I created this init script. Hope it's useful to someone!
NOTES:
- Requires a "pms" user created to run the PS3 Media server. Running with root is always a bad idea...

- Logging is enabled at /var/log/pms.log. Also can be set in PMS_LOG var.
UPDATE:
- The previous version had a bug, the PMS.conf was not read. The current code works fine, but needs a support script listed after the int script
- The PMS_HOME value must be adjusted to the current PMS install directory
- Variable declaration order was messed up.. Now corrected!
/etc/init.d/pms
- Code: Select all
#!/bin/sh
#
# PS3 MEDIA SERVER (PMS)
#
### BEGIN INIT INFO
# Provides: pms
# Required-Start: $ALL $remote_fs
# Required-Stop: $null
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: PS3 Media Server daemon
# Description: PS3 Media Server daemon
### END INIT INFO
PMS_USER=pms
PMS_GROUP=users
PMS_PORT=5001
JAVA="/usr/bin/java"
PMS_HOME="/opt/pms"
PMS_JAR="$PMS_HOME/pms.jar"
PMS_CMD="${JAVA} -Xmx768M -Djava.encoding=UTF-8 -Djava.net.preferIPv4Stack=true -jar ${PMS_JAR} console"
PMS_STARTCMD="${PMS_HOME}/pmsd"
PMS_PIDFILE=/var/run/pms.pid
PMS_LOG=/var/log/pms.log
test -f $PMS_JAR || { echo "$PMS_JAR not installed";
if [ "$1" = "stop" ]; then exit 0;
else exit 5; fi; }
. /etc/rc.status
# Reset status of this service
rc_reset
# Get PID for PMS cmd
get_pid ()
{
for pid in `ls /proc`; do
if [ -d /proc/$pid ] && [ -f /proc/$pid/cmdline ]; then
if [ "$1" = "$(</proc/$pid/cmdline)" ]; then
# return with current pid
return
fi
fi
done
pid=0
}
# checkport <port>
# returns 1 if port_used, 0 if not used
check_port()
{
if netstat -nlept 2>/dev/null | grep --regexp=":$PMS_PORT " &>/dev/null ; then
return 1
else
return 0
fi
}
# Check if PMS has a PID
check_pid()
{
get_pid `eval echo ${PMS_CMD} | sed -e 's/ //g'`
if [ 0 = $pid ]; then
return 0
else
return 1
fi
}
case "$1" in
start)
echo -n "PS3 Media Server "
check_pid
if ! [ 0 = $? ]; then
echo "already running"
rc_failed
rc_status -v1
rc_exit
fi
check_port
if ! [ 0 = $? ]; then
echo "port $PMS_PORT already in use"
rc_failed
rc_status -v1
rc_exit
fi
export PMS_HOME PMS_CMD
/sbin/startproc -f -u $PMS_USER -g $PMS_GROUP -p ${PMS_PIDFILE} ${PMS_STARTCMD} >> ${PMS_LOG} 2>&1
check_pid
if [ 0 = $? ]; then
echo "failed start, couldn't obtain PID"
rc_failed
rc_status -v1
rc_exit
fi
echo $pid > ${PMS_PIDFILE}
rc_status -v
;;
stop)
echo -n "Shutting down PS3 Media Server "
check_pid
if [ 0 = $? ]; then
echo "not running"
rc_failed
rc_status -v1
rc_exit
fi
/sbin/killproc -TERM -p ${PMS_PIDFILE} ${JAVA}
rc_status -v
;;
restart)
$0 stop
$0 start
rc_status
;;
status)
echo -n "Checking for service PS3 Media Server "
/sbin/checkproc -p $PMS_PIDFILE ${JAVA}
rc_status -v
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
exit 1
;;
esac
rc_exit
/opt/pms/pmsd
- Code: Select all
#!/bin/sh
# Go to the PMS Home dir
cd ${PMS_HOME}
# Execute the command to start PMS
exec ${PMS_CMD}