aboutsummaryrefslogtreecommitdiff
path: root/multimedia/plexmediaserver/rc.plexmediaserver
blob: 93598b361c91e82404146d0ca6e6aa98920b6549 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/sh
 
# /etc/rc.d/rc.plexmediaserver - Start/stop/restart the plexmediaserver daemon.
# To make plexmediaserver start automatically at boot, make this
# file executable: chmod 0755 /etc/rc.d/rc.plexmediaserver and add it 
# to slackware's startup scripts (ie: rc.local)
#
 
PIDFILE="/var/run/plexmediaserver.pid"
 
plexmediaserver_start() {
    echo "Starting plexmediaserver..."
    CHECK=$(ps aux | grep /usr/bin/start_pms | grep -v grep)
    STATUS=$?
 
    # make sure plexmediaserver isn't running yet
    if [ "$STATUS" == "1" ]; then
       touch $PIDFILE
       chown plex:plex $PIDFILE
 
        # Start plexmediaserver
       sudo -u plex /usr/bin/start_pms &
    else
        echo "plexmediaserver is already active and running under PID: $(cat $PIDFILE)"
        echo "if you think this is wrong, remove the offending PID file"
        echo "and restart plexmediaserver"
        exit 1
    fi
}
 
plexmediaserver_stop() {
    echo -n "Stopping plexmediaserver..."
    if [ -r $PIDFILE ]; then
        kill $(cat $PIDFILE)
        killall "Plex Media Server"
        rm $PIDFILE
        echo "done"
    else
        killall "Plex Media Server"
        rm $PIDFILE
        echo "done"
    fi
}
 
# Let's see how we are being called.
case "$1" in
  start)
    plexmediaserver_start
    ;;
  stop)
    plexmediaserver_stop
    ;;
  restart)
    plexmediaserver_start
    sleep 3
    plexmediaserver_stop
    ;;
  *)
    echo "Usage: $(basename $0) {start|stop|restart}"
    exit 1
    ;;
esac