~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

Viewing changes to utopic/etc/init.d/varnishncsa

  • Committer: Dimitri John Ledkov
  • Date: 2014-11-19 12:58:41 UTC
  • Revision ID: dimitri.j.ledkov@intel.com-20141119125841-98dr37roy8dvcv3b
auto update

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /bin/sh
2
 
 
3
 
### BEGIN INIT INFO
4
 
# Provides:          varnishncsa
5
 
# Required-Start:    $local_fs $remote_fs $network
6
 
# Required-Stop:     $local_fs $remote_fs $network
7
 
# Default-Start:     2 3 4 5
8
 
# Default-Stop:      0 1 6
9
 
# Short-Description: Start HTTP accelerator log daemon
10
 
# Description:       This script provides logging for varnish
11
 
### END INIT INFO
12
 
 
13
 
# Source function library
14
 
. /lib/lsb/init-functions
15
 
 
16
 
NAME=varnishncsa
17
 
DESC="HTTP accelerator log deamon"
18
 
PATH=/sbin:/bin:/usr/sbin:/usr/bin
19
 
DAEMON=/usr/bin/$NAME
20
 
PIDFILE=/var/run/$NAME/$NAME.pid
21
 
LOGFILE=/var/log/varnish/varnishncsa.log
22
 
USER=varnishlog
23
 
DAEMON_OPTS="-a -w ${LOGFILE} -D -P ${PIDFILE}"
24
 
 
25
 
# Include defaults if available
26
 
if [ -f /etc/default/$NAME ] ; then
27
 
        . /etc/default/$NAME
28
 
fi
29
 
 
30
 
# If unset, or set to "0" or "no", exit
31
 
if [ -z "${VARNISHNCSA_ENABLED}" ] || \
32
 
   [ "${VARNISHNCSA_ENABLED}" = "0" ] || \
33
 
   [ "${VARNISHNCSA_ENABLED}" = "no" ]; then
34
 
  exit 0;
35
 
fi
36
 
 
37
 
test -x $DAEMON || exit 0
38
 
 
39
 
start_varnishncsa() {
40
 
    output=$(/bin/tempfile -s.varnish)
41
 
    log_daemon_msg "Starting $DESC" "$NAME"
42
 
    create_pid_directory
43
 
    if start-stop-daemon --start --quiet --pidfile ${PIDFILE} \
44
 
        --chuid $USER --exec ${DAEMON} -- ${DAEMON_OPTS} \
45
 
        > ${output} 2>&1; then
46
 
        log_end_msg 0
47
 
    else
48
 
        log_end_msg 1
49
 
        cat $output
50
 
        exit 1
51
 
    fi
52
 
    rm $output
53
 
}
54
 
 
55
 
stop_varnishncsa(){
56
 
    log_daemon_msg "Stopping $DESC" "$NAME"
57
 
    if start-stop-daemon --stop --quiet --pidfile $PIDFILE \
58
 
        --retry 10 --exec $DAEMON; then
59
 
        log_end_msg 0
60
 
    else
61
 
        log_end_msg 1
62
 
    fi
63
 
}
64
 
 
65
 
reload_varnishncsa(){
66
 
    log_daemon_msg "Reloading $DESC" "$NAME"
67
 
    if kill -HUP $(cat $PIDFILE) >/dev/null 2>&1; then
68
 
        log_end_msg 0
69
 
    else
70
 
        log_end_msg 1
71
 
        exit 1
72
 
    fi
73
 
}
74
 
 
75
 
status_varnishncsa(){
76
 
    status_of_proc -p "${PIDFILE}" "${DAEMON}" "${NAME}"
77
 
    exit $?
78
 
}
79
 
 
80
 
create_pid_directory() {
81
 
    install -o $USER -g $USER -d $(dirname $PIDFILE)
82
 
}
83
 
 
84
 
case "$1" in
85
 
    start)
86
 
        start_varnishncsa
87
 
        ;;
88
 
    stop)
89
 
        stop_varnishncsa
90
 
        ;;
91
 
    reload)
92
 
        reload_varnishncsa
93
 
        ;;
94
 
    status)
95
 
        status_varnishncsa
96
 
        ;;
97
 
    restart|force-reload)
98
 
        $0 stop
99
 
        $0 start
100
 
        ;;
101
 
    *)
102
 
        log_success_msg "Usage: $0 {start|stop|restart|force-reload|reload}"
103
 
        exit 1
104
 
        ;;
105
 
esac
106
 
 
107
 
exit 0