-
Notifications
You must be signed in to change notification settings - Fork 1
/
starman
executable file
·145 lines (125 loc) · 2.84 KB
/
starman
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
#
# starman RHEL/CENTOS init script for Starman web server
#
# chkconfig: 345 56 50
# description: Runs the Starman web server in production environments.
# Uses start_server superdaemon for graceful restarts and
# runs as user/group "nobody." Expects local Perl install
# with plenv.
# HOME and environment setup must be customized for environment.
# See also perldoc Starman and Server::Starter.
# Repository: https://github.com/mla/starman-init
#
# pidfile: /var/run/starman.pid
# app settings
HOME=/home/myhome
APP_HOME=$HOME/sites/myapp
APP=$APP_HOME/app.psgi
APP_NAME=$(basename $(readlink -f $0))
START_SERVER=$APP_HOME/vendor/perl5/bin/start_server
STARMAN=$APP_HOME/vendor/perl5/bin/starman
PORT=5000
WORKERS=32
USER=nobody
GROUP=nobody
PID_FILE=/var/run/$APP_NAME.pid
STATUS_FILE=/var/run/$APP_NAME.status
LOCK_FILE=/var/lock/subsys/$APP_NAME
LOGDIR=/var/log/$APP_NAME
cd $HOME || exit 3
# configure app perl
export PATH=$HOME/.plenv/bin:/sbin:/bin:/usr/bin:/usr/sbin
eval "$(plenv init -)"
# Source function library.
. /etc/init.d/functions
# Get config.
test -f /etc/sysconfig/network && . /etc/sysconfig/network
# Check that we are root
[ `id -u` = 0 ] || { echo "must be root"; exit 1; }
# Check that networking is up.
[ "${NETWORKING}" = "yes" ] || exit 0
RETVAL=0
start(){
echo -n $"Starting $APP_NAME: "
mkdir -p $LOGDIR
daemon --pidfile $PID_FILE \
$START_SERVER \
--interval=5 \
--port=$PORT \
--signal-on-hup=QUIT \
--signal-on-term=QUIT \
--pid-file=$PID_FILE \
--status-file=$STATUS_FILE \
--backlog=1024 \
-- \
$STARMAN \
--preload-app \
--workers $WORKERS \
--user $USER \
--group $GROUP \
--error-log $LOGDIR/error.log \
--access-log $LOGDIR/access.log \
$APP \
&
RETVAL=$?
echo
touch $LOCK_FILE
return $RETVAL
}
stop(){
echo -n $"Stopping $APP_NAME: "
killproc -p $PID_FILE $APP_NAME
RETVAL=$?
echo
rm -f $LOCK_FILE
return $RETVAL
}
graceful(){
if [ -s $PID_FILE ]; then
echo -n $"Gracefully restarting $APP_NAME: "
$START_SERVER \
--pid-file $PID_FILE \
--status-file $STATUS_FILE \
--restart
RETVAL=$?
echo
return $RETVAL
else
echo $"Not running."
start
fi
}
restart(){
stop
start
}
condrestart(){
[ -e $LOCK_FILE ] && restart
return 0
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p $PID_FILE $APP_NAME
;;
graceful)
graceful
;;
restart)
restart
;;
condrestart)
condrestart
;;
*)
echo $"Usage: $0 {start|stop|status|graceful|restart|condrestart|reload}"
RETVAL=1
esac
exit $RETVAL