Skip to content

Instantly share code, notes, and snippets.

@typomedia
Last active March 24, 2017 09:57
Show Gist options
  • Save typomedia/6469961 to your computer and use it in GitHub Desktop.
Save typomedia/6469961 to your computer and use it in GitHub Desktop.
Plex Media Server Init Script
#!/bin/sh
### BEGIN INIT INFO
# Provides: plexmediaserver
# Required-Start: $remote_fs $syslog $all
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Plex Media Server
# Description: Plex is a smart Media Server application for playing Music, Movies and other media
# Author: Typomedia Foundation
# Version: 1.4
### END INIT INFO
PATH=/bin:/usr/bin:/sbin:/usr/sbin
NAME=plex
DESC="Plex Media Server"
DAEMON=/usr/sbin/start_pms
PIDFILE=/var/run/plex.pid
export PLEX_RUN_USER="plex"
[ -x $DAEMON ] || exit 0
. /lib/lsb/init-functions
start_daemon () {
start-stop-daemon --start --quiet --background \
--make-pidfile --pidfile $PIDFILE \
--chuid $PLEX_RUN_USER \
--exec $DAEMON
}
stop_daemon () {
killall -9 "Plex Media Server" >/dev/null 2>&1
#killall -9 "Plex DLNA Server" >/dev/null 2>&1
}
reload_daemon () {
start-stop-daemon --stop --quiet --signal 1 \
--pidfile $PIDFILE \
--exec $DAEMON
}
case "$1" in
start)
log_daemon_msg "Starting $DESC" "$NAME"
start_daemon
log_end_msg 0
;;
stop)
log_daemon_msg "Stopping $DESC" "$NAME"
stop_daemon
log_end_msg 0
;;
reload)
log_daemon_msg "Reloading $DESC" "$NAME"
reload_daemon
log_end_msg 0
;;
restart|force-reload)
log_daemon_msg "Restarting $DESC" "$NAME"
stop_daemon
sleep 1
start_daemon
log_end_msg 0
;;
status)
status_of_proc $DAEMON "$DESC" && exit 0 || exit $?
;;
*)
log_action_msg "Usage: service $NAME {start|stop|reload|restart|status}" || true
exit 2
;;
esac
exit 0
@typomedia
Copy link
Author

running with Plex Media Server 0.9.8.14.263-139ddbc_amd64.deb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment