aboutsummaryrefslogtreecommitdiffstats
path: root/www/interchange/files/interchange.sh
blob: 449cb9e14b950e368eeb5939348da1552a39e37e (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
#!/bin/sh

RUNDIR=/var/run/interchange
LOGDIR=/var/log/interchange
ICUSER=$(cat %%PREFIX%%/interchange/_uid)
PIDFILE=${RUNDIR}/interchange.pid
SOCKFILE=${RUNDIR}/interchange.sock

OPTS="SocketFile=${SOCKFILE} IPCsocket=${SOCKFILE}.ipc PIDfile=${PIDFILE}"
OPTS="${OPTS} --pidfile=${PIDFILE} --log=${LOGDIR}/error.log --rundir=${RUNDIR}"

case "$1" in
start)
    [ -d ${RUNDIR} ] || \
        (mkdir ${RUNDIR} && chown ${ICUSER}:${ICUSER} ${RUNDIR})
    [ -d ${LOGDIR} ] || \
        (mkdir ${LOGDIR} && chown ${ICUSER}:${ICUSER} ${LOGDIR})

    if [ -x %%PREFIX%%/bin/interchange ]; then
        su -m ${ICUSER} \
            -c "%%PREFIX%%/bin/interchange ${OPTS} >/dev/null" && \
        echo -n ' interchange'
    fi
    ;;
stop)
    if [ -r ${PIDFILE} ]; then
        kill $(cat ${PIDFILE}) && \
            echo -n ' interchange'
    fi
    ;;
*)
    echo "Usage: `basename $0` {start|stop}" >&2
    ;;
esac