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
  
146
  
147
  
148
  
149
  
150
  
151
  
152
  
153
  
154
  
155
  
156
  
157
  
158
  
159
  
160
  
161
  
162
  
163
  
164
  
165
  
166
  
167
  
168
  
169
  
170
  
171
  
172
  
173
  
174
  
175
  
176
  
177
  
178
  
179
  
180
  
181
  
182
  
183
  
184
  
185
  
186
  
187
  
188
  
189
  
190
  
191
  
192
  
193
  
194
  
195
  
196
  
197
  
198
  
199
  
200
  
201
  
202
  
203
  
204
  
205
  
206
  
207
  
208
  
209
  
210
  
211
  
212
  
213
  
214
  
215
  
216
  
217
  
218
  
219
  
220
  
221
  
222
  
223
  
224
  
225
  
226
  
227
  
228
  
229
  
230
  
231
  
232
  
233
  
234
  
235
  
236
  
237
  
238
  
239
  
240
  
241
  
242
  
243
  
244
  
245
  
246
  
247
  
248
  
249
  
250
  
251
  
252
  
253
  
254
  
255
  
256
  
257
  
258
  
#!/bin/sh 
# init.d script for Roxen. Set the variables below to something fitting.. 
# This is only an example script. 
# $Id$ 
############# 
### BEGIN INIT INFO 
# Provides:         roxen 
# Required-Start:   $local_fs $syslog $named $network $time 
# Required-Stop:    $local_fs $syslog $named $network 
# Should-Start: 
# Should-Stop: 
# Default-Start:    2 3 4 5 
# Default-Stop:             0 1 6 
# Description:              Roxen Webserver 
### END INIT INFO 
 
# Configurations collection directory. If available, it overrides 
# roxenhome below. 
# 
roxenconfdir=/etc/roxen 
 
# The server directory where the 'start' script is located, if available. 
# 
roxenhome=/usr/local/roxen 
 
# Set these to kill all processes owned by wwwuser on stop. Useful to 
# reap CGI scripts. 
# 
# killallwww=yes 
# wwwuser=www 
 
umask 022 
 
# If you want to start with another configuration directory. The path 
# is relative to the server-X.Y.Z directory. 
# 
# configdir=../configurations 
 
# Here you can add extra flags to the start script, like enabling or 
# disabling threads. 
#  
# flags="--with-threads" 
# flags="--without-threads" 
 
# The file to store the process ids in, to allow this script to stop, 
# reload and restart the server. By default it's placed in the 
# configuration directory, which ensures that it doesn't accidentally 
# overwrite the pid file for another server instance. 
# 
# pidfile=$configdir/_roxen_pid 
 
 
### You should not _have_ to change anything below here... 
 
# chkconfig: - 90 20 
# description:  Roxen 
 
errexit=1 
okexit=0 
 
if [ -f /lib/svc/share/smf_include.sh -a "x$SMF_FMRI" != x ]; then 
 
    # Looks like we've been called from the Solaris svc system. 
 
    . /lib/svc/share/smf_include.sh 
 
    errexit="$SMF_EXIT_ERR_CONFIG" 
    okexit="$SMF_EXIT_OK" 
 
    # roxen/dir ==> roxenhome 
    if svcprop -q -p roxen/dir ${SMF_FMRI}; then 
        val=`svcprop -p roxen/dir ${SMF_FMRI}` 
        if [ "$val" != "\"\"" ] ; then 
            roxenhome="$val" 
        fi 
    fi 
 
    # roxen/confdir ==> roxenconfdir 
    if svcprop -q -p roxen/confdir ${SMF_FMRI}; then 
        val=`svcprop -p roxen/confdir ${SMF_FMRI}` 
        if [ "$val" != "\"\"" ] ; then 
            roxenconfdir="$val" 
        fi 
    fi 
fi 
 
find_server_dir() 
{ 
  ( 
    cd "$roxenhome" >/dev/null 2>&1 && 
    for dir in server*; do 
      ( cd "$dir" >/dev/null 2>&1 && 
        test -f "$configdir/server_version" && 
        echo "$roxenhome/`cat \"$configdir/server_version\"`" 
      ) && return 
    done 
    echo "$roxenhome/server" 
  ) 
} 
 
# Some systems have stupid rc scripts that are written in shells with job 
# support (read Linux/bash), and send SIGHUP when they finish. 
trap "" 1 
 
run_server() 
{ 
    test x"$pidfile" = x && pidfile="$configdir"/_roxen_pid 
    flags="$flags --pid-file=$pidfile" 
 
    if [ -x "$roxenhome/start" ]; then :; else 
      echo "Cannot find a Roxen installation in $roxenhome." 
      exit $errexit 
    fi 
     
 case $1 in 
  'start_msg') 
    echo "Start Roxen in $roxenhome." 
    exit $okexit 
  ;; 
  'stop_msg') 
    echo "Stop Roxen in $roxenhome." 
    exit $okexit 
  ;; 
 
  'start') 
    echo "Starting Roxen in $roxenhome..." 
    cd $roxenhome && { 
      ./start $flags 2>/dev/null && { 
        echo "Roxen started." 
        exit $okexit 
      } 
      echo "Failed to start Roxen. Already running?" 
    } 
  ;; 
 
  'reload') 
    echo "Reloading configurations in Roxen in $roxenhome..." 
    cd $roxenhome && { 
      echo "Sending SIGHUP to Roxen process." 
      ./start --signal 1 $flags 2>/dev/null && exit $okexit 
      echo "Roxen doesn't seem to be running." 
    } 
  ;; 
 
  'restart') 
    echo "Restarting Roxen in $roxenhome..." 
    cd $roxenhome && { 
      ./start --restart $flags 2>/dev/null && { 
        echo "Roxen started." 
        exit $okexit 
      } 
      echo "Failed to restart Roxen." 
    } 
  ;; 
 
  'stop') 
    echo "Stopping Roxen in $roxenhome..." 
    cd "$roxenhome" && { 
      ./start --stop $flags 2>/dev/null && { 
        echo "Roxen stopped." 
        exit $okexit 
      } 
      echo "Failed to stop Roxen." 
    } 
  ;; 
 
  'status') 
    cd "$roxenhome" && { 
      if ./start --signal 0 $flags 2>/dev/null; then 
        echo "Roxen is running." 
        status=0 
        return 0 
      fi 
      echo "Roxen is not running." 
    } 
  ;; 
 
  'debug') 
    cd "$roxenhome" && { 
      echo "Sending SIGQUIT to Roxen process $pid." 
      ./start --signal QUIT $flags 2>/dev/null && exit $okexit 
      echo "Roxen doesn't seem to be running." 
    } 
  ;; 
 
  *) 
    echo "Usage: $0 [start|stop|status|start_msg|stop_msg|restart|reload|debug]" 
  ;; 
 esac 
 exit $errexit 
} 
 
get_variables() 
{ 
    configdir="$1" 
    flags="$flags --config-dir=$configdir" 
     
    echo "Configuration dir: $configdir" 
    test -r "$configdir"/_startparams && source "$configdir"/_startparams 
    if [ ! -d "$roxenhome" ] 
    then 
        # The roxen dir specified in _startparams does not exist, 
      # let's pick the latest existing dir instead. 
      oldroxenhome=$roxenhome 
        roxenhome=`ls -td \`dirname $oldroxenhome\`/roxen-* | head -1` 
        if [ -d "$roxenhome" ] 
        then 
                echo "Fatal: No Roxen dir found, exiting!" >&2 
                exit $errexit 
        fi 
        echo "Warning: $oldroxenhome does not exist, trying $roxenhome instead." >&2 
    fi 
    test -r "$configdir"/_environment && source "$configdir"/_environment 
    if [ ! -d `dirname "$ROXEN_PID_FILE"` ] 
    then 
        echo "`dirname $ROXEN_PID_FILE` does not exist, creating." 
        mkdir -p `dirname "$ROXEN_PID_FILE"`  
    fi 
    test -n "$ROXEN_PID_FILE" && pidfile="$ROXEN_PID_FILE" 
    if [ x"$ROXEN_LOGDIR" != x ] 
    then 
        DEBUGLOG="$ROXEN_LOGDIR"/debug/default 
        export DEBUGLOG 
    fi 
} 
 
if [ -d "$roxenconfdir" ] 
then 
    if [ -z "$1" ] 
    then 
        echo "Usage: $0 [start|stop|status|start_msg|stop_msg|restart|reload|debug] <instance name>" 
        exit $errexit 
    fi 
    if [ -z "$2" ] 
    then 
        flagsorig="$flags" 
        for f in "$roxenconfdir"/* 
        do 
            flags="$flagsorig" 
            get_variables "$f" 
            run_server "$1" 
        done 
    else 
        get_variables "$roxenconfdir"/"$2" 
        run_server "$1" 
    fi 
else 
    if test x"$configdir" = x 
    then 
        configdir=../configurations 
    else 
        flags="$flags --config-dir=$configdir" 
    fi 
     
    roxenhome=`find_server_dir` 
    run_server "$@" 
fi