aboutsummaryrefslogtreecommitdiffstats
path: root/config/sysvinit-thin.example
blob: 0155ff8c3b6b74cc3ed507c91132b2456eb17994 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#! /bin/sh
### BEGIN INIT INFO
# Provides:          application-thin-!!(*= $site *)!!
# Required-Start:    $local_fs $network
# Required-Stop:     $local_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Starts the Thin app server for the "!!(*= $site *)!!" site
# Description:       The Thin app server for the "!!(*= $site *)!!" site
### END INIT INFO

# This example sysvinit script is based on the helpful example here:
# http://richard.wallman.org.uk/2010/02/howto-deploy-a-catalyst-application-using-fastcgi-and-nginx/

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=!!(*= $site *)!!
SITE_HOME=!!(*= $vhost_dir *)!!/!!(*= $vcspath *)!!
DESC="Alaveteli app server"
USER=!!(*= $user *)!!
RAILS_ENV=!!(*= $rails_env *)!!

set -e

# Check that the Daemon can be run
CURRENT_USER=$(whoami)
if [ "$CURRENT_USER" = "$USER" ]
  then
    cd $SITE_HOME && bundle exec thin --version > /dev/null 2>&1 || exit 0
  else
    su -l -c "cd $SITE_HOME && bundle exec thin --version &> /dev/null || exit 0" $USER
fi

start_daemon() {
  echo -n "Starting $DESC: "
  cd "$SITE_HOME" && bundle exec thin \
    --environment=$RAILS_ENV \
    --user="$USER" \
    --group="$USER" \
    --address=127.0.0.1 \
    --daemonize \
    --quiet \
    start || true
  echo "$NAME."
}

stop_daemon() {
  echo -n "Stopping $DESC: "
  cd "$SITE_HOME" && bundle exec thin --quiet stop || true
  echo "$NAME."
}

restart_daemon() {
  echo -n "Restarting $DESC: "
  cd "$SITE_HOME" && bundle exec thin --onebyone --quiet restart || true
  echo "$NAME."
}

case "$1" in
  start)
    start_daemon
    ;;
  stop)
    stop_daemon
    ;;
  reload|restart|force-reload)
    restart_daemon
    ;;
  *)
    N=/etc/init.d/$NAME
    echo "Usage: $N {start|stop|reload|restart|force-reload}" >&2
    exit 1
    ;;
esac

exit 0