aboutsummaryrefslogtreecommitdiffstats
path: root/audio/slimserver/files/slimserver.sh.in
blob: d4617c1cc2a828fe62795ca4323b020a3a68414a (plain) (blame)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/sh
#
# $FreeBSD$
#

# PROVIDE: slimserver
# REQUIRE: LOGIN
# KEYWORD: FreeBSD shutdown

#
# Add the following lines to /etc/rc.conf to enable slimserver:
#
#slimserver_enable="YES"
#

. %%RC_SUBR%%

name=slimserver
start_precmd="slimserver_start_precmd"
stop_cmd="slimserver_stop"
rcvar=`set_rcvar`

command=%%PREFIX%%/%%SLIMDIR%%/slimserver.pl
pidfile=/var/run/${name}.pid
logfile=/var/log/slimserver.log
statedir=/var/db/slimserver
cachedir=${statedir}/cache
playlistdir=${statedir}/playlists
conffile=${statedir}/slimserver.conf
u=slimserv
g=slimserv
command_args="--daemon --prefsfile=${conffile} --logfile=${logfile} --user=${u} --group=${g} --pidfile=${pidfile}"

PGREP=%%PGREPBASE%%/bin/pgrep

slimserver_start_precmd()
{
    if [ ! -d ${statedir} ]; then
        mkdir -p ${statedir}
        chown -R ${u}:${g} ${statedir}
    fi
    if [ ! -d ${cachedir} ]; then
        mkdir -p ${cachedir}
        chown -R ${u}:${g} ${cachedir}
    fi
    if [ ! -d ${playlistdir} ]; then
        mkdir -p ${playlistdir}
        chown -R ${u}:${g} ${playlistdir}
    fi
    if [ ! -f ${conffile} ]; then
        touch ${conffile}
        chown ${u}:${g} ${conffile}
    fi
    if [ ! -f ${logfile} ]; then
        touch ${logfile}
        chown ${u}:${g} ${logfile}
    fi
}

slimserver_stop()
{
    if [ ! -f ${pidfile} ]; then
        exit
    fi
    echo 'Stopping SlimServer.'
    rc_pid=`cat ${pidfile}`
    rc_pid=`${PGREP} -u ${u} | grep ${rc_pid}`
    if [ -n "${rc_pid}" ]; then
        # Should be mDNSResponderPosix, but the port truncates
        rc_pids="${rc_pid} `${PGREP} -u ${u} mDNSResponderPos`"

        kill $sig_stop $rc_pids
        wait_for_pids $rc_pids
    else
        echo "${name} not running? (check ${pidfile})"
    fi

    rm -f ${pidfile}
}

load_rc_config ${name}

slimserver_enable=${slimserver_enable:-"NO"}
slimserver_flags=${slimserver_flags:-""}

run_rc_command "$1"