summaryrefslogtreecommitdiff
blob: 9862a29da2f9b79fd36c1a2a42400f9d58213281 (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
#!/sbin/openrc-run
# Copyright 1999-2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

pidfile="/var/run/srsd.pid"
command="/usr/bin/srsd"
command_args="${SRSD_OPTS}"

depend() {
    use logger
}

start_pre() {
    if [[ ! -z ${SRSD_SECRET_FILE} ]]; then
        # check for secret file
        checkpath --file --owner root:root --mode 0644 ${SRSD_SECRET_FILE}
        
        # srsd complains if the secret file is empty
        # check for characters in it 
        grep -q '.' ${SRSD_SECRET_FILE}

        # grep returns 0 if a match has been found
        # 1 otherwise
        local retval=$?
        if [[ $retval -ne 0 ]]; then
            eerror "Secret file \"${SRSD_SECRET_FILE}\" must NOT be empty."
            return 1
        fi
    fi

    return 0
}

start() {
    ebegin 'Starting srsd'
    start-stop-daemon \
        --start \
        --background \
        --pidfile ${pidfile} \
        --make-pidfile \
        --exec ${command} \
        -- ${command_args}
    eend $?
}

stop() {
    ebegin 'Stopping srsd'
    start-stop-daemon \
        --stop \
        --pidfile ${pidfile} \
        --exec ${command}
    eend $?
}