~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

Viewing changes to vivid/etc/init.d/unicorn

  • 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
### BEGIN INIT INFO
 
3
# Provides:          unicorn
 
4
# Required-Start:    $local_fs $remote_fs
 
5
# Required-Stop:     $local_fs $remote_fs
 
6
# Default-Start:     2 3 4 5
 
7
# Default-Stop:      0 1 6
 
8
# Short-Description: unicorn initscript
 
9
# Description:       unicorn
 
10
### END INIT INFO
 
11
 
 
12
set -e
 
13
 
 
14
NAME=unicorn
 
15
DESC="Unicorn web server"
 
16
 
 
17
. /lib/lsb/init-functions
 
18
 
 
19
if [ -f /etc/default/unicorn ]; then
 
20
  . /etc/default/unicorn
 
21
fi
 
22
 
 
23
DAEMON=/usr/bin/unicorn
 
24
PID=${PID-/run/unicorn.pid}
 
25
 
 
26
run_by_init() {
 
27
    ([ "${previous-}" ] && [ "${runlevel-}" ]) || [ "${runlevel-}" = S ]
 
28
}
 
29
 
 
30
exit_with_message() {
 
31
  if ! run_by_init; then
 
32
    log_action_msg "$1 Not starting."
 
33
  fi
 
34
  exit 0
 
35
}
 
36
 
 
37
check_config() {
 
38
  if [ $CONFIGURED != "yes" ]; then
 
39
    exit_with_message "Unicorn is not configured (see /etc/default/unicorn)."
 
40
  fi
 
41
}
 
42
 
 
43
check_app_root() {
 
44
  if ! [ -d $APP_ROOT ]; then
 
45
    exit_with_message "Application directory $APP_ROOT is not exist."
 
46
  fi
 
47
}
 
48
 
 
49
set -u
 
50
 
 
51
case "$1" in
 
52
  start)
 
53
        check_config
 
54
        check_app_root
 
55
 
 
56
        log_daemon_msg "Starting $DESC" $NAME || true
 
57
        if start-stop-daemon --start --quiet --oknodo --pidfile $PID --exec $DAEMON -- $UNICORN_OPTS; then
 
58
          log_end_msg 0 || true
 
59
        else
 
60
          log_end_msg 1 || true
 
61
        fi
 
62
              ;;
 
63
  stop)
 
64
        log_daemon_msg "Stopping $DESC" $NAME || true
 
65
        if start-stop-daemon --stop --signal QUIT --quiet --oknodo --pidfile $PID; then
 
66
          log_end_msg 0 || true
 
67
        else
 
68
          log_end_msg 1 || true
 
69
        fi
 
70
        ;;
 
71
  force-stop)
 
72
        log_daemon_msg "Forcing stop of $DESC" $NAME || true
 
73
        if start-stop-daemon --stop --quiet --oknodo --pidfile $PID; then
 
74
          log_end_msg 0 || true
 
75
        else
 
76
          log_end_msg 1 || true
 
77
        fi
 
78
        ;;
 
79
  restart|force-reload)
 
80
        log_daemon_msg "Restarting $DESC" $NAME || true
 
81
        start-stop-daemon --stop --quiet --oknodo --pidfile $PID
 
82
        sleep 1
 
83
        if start-stop-daemon --start --quiet --oknodo --pidfile $PID --exec $DAEMON -- $UNICORN_OPTS; then
 
84
          log_end_msg 0 || true
 
85
        else
 
86
          log_end_msg 1 || true
 
87
        fi
 
88
        ;;
 
89
  reload)
 
90
        log_daemon_msg "Reloading $DESC" $NAME || true
 
91
        if start-stop-daemon --stop --signal HUP --quiet --oknodo --pidfile $PID; then
 
92
          log_end_msg 0 || true
 
93
        else
 
94
          log_end_msg 1 || true
 
95
        fi
 
96
        ;;
 
97
  reopen-logs)
 
98
        log_daemon_msg "Relopening log files of $DESC" $NAME || true
 
99
        if start-stop-daemon --stop --signal USR1 --quiet --oknodo --pidfile $PID; then
 
100
          log_end_msg 0 || true
 
101
        else
 
102
          log_end_msg 1 || true
 
103
        fi
 
104
        ;;
 
105
  status)
 
106
        status_of_proc -p $PID $DAEMON $NAME && exit 0 || exit $?
 
107
        ;;
 
108
  *)
 
109
        log_action_msg "Usage: $0 <start|stop|restart|force-reload|reload|force-stop|reopen-logs|status>" || true
 
110
        exit 1
 
111
        ;;
 
112
esac