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
  
#!/bin/sh 
# 
# /Library/StartupItems/Roxen/Roxen 
# 
# StartupItem script for Roxen. Set the variables 
# below to something fitting. This is only an example script. 
# 
 
# If the directory /etc/roxen exists, we'll loop through all 
# directories within it and apply an action to all servers,  
# or if an instance name has been specified, we'll only do 
# that one. 
# 
# Example, starts only the instance with config dir named "default":  
# /Library/StartupItems/Roxen/Roxen start default 
# 
# Example, starts all configured instances within /etc/roxen: 
# /Library/StartupItems/Roxen/Roxen start 
 
# Check if zero arguments 
# 
if [ -z $1 ] ; then 
    echo "Usage: $0 [start|stop|restart|status|debug] <instance name>" 
    exit 1 
fi 
 
useconfig=$2 
 
# Setup environment 
# 
test -r /etc/rc.common || exit 1 
. /etc/rc.common 
 
# The server directory where the 'start' script is located. 
# 
roxenhome=/usr/local/roxen 
 
# File creation mask 
# 
umask 022 
 
# If you want to start with another configuration directory. The path 
# is relative to the server-X.Y.Z directory. 
# 
configdir= 
#configdir=../configurations 
 
# Here you can add extra flags to the start script, like enabling or 
# disabling threads. 
#  
flags= 
#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= 
#pidfile=$configdir/_roxen_pid 
 
roxenconfdir=/etc/roxen 
 
### You should not _have_ to change anything below here... 
 
if test x$configdir = x; then 
  configdir=../configurations 
else 
  flags="$flags --config-dir=$configdir" 
fi 
 
test x$pidfile = x && pidfile=$configdir/_roxen_pid 
flags="$flags --pid-file=$pidfile" 
 
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" 
        ) 
} 
roxenhome=`find_server_dir` 
 
 
StartService() 
{ 
    if [ "${ROXEN:=-NO-}" = "-YES-" ]; then 
        ConsoleMessage "Starting Roxen in $roxenhome..." 
        cd $roxenhome && { 
            if [ -x $roxenhome/start ]; then 
                ./start $flags 2>/dev/null && { 
                    ConsoleMessage "Roxen started." 
                    return 
                } 
                ConsoleMessage "Failed to start Roxen. Already running?" 
            else 
                ConsoleMessage "Cannot find a Roxen installation in $roxenhome." 
            fi 
        } 
    else 
        ConsoleMessage "Service controller ROXEN in /etc/hostconfig is disabled." 
    fi 
} 
 
StopService() 
{ 
    ConsoleMessage "Stopping Roxen in $roxenhome..." 
    cd $roxenhome && { 
        if [ -x $roxenhome/start ]; then 
            ConsoleMessage "Sending SIGTERM to Roxen process." 
            ./start --stop $flags 2>/dev/null 
            ConsoleMessage "Roxen stopped." 
        else 
            ConsoleMessage "Cannot find a Roxen installation in $roxenhome." 
        fi 
    } 
} 
 
RestartService() 
{ 
    ConsoleMessage "Restarting Roxen in $roxenhome..." 
    cd $roxenhome && { 
        if [ -x $roxenhome/start ]; then 
            ConsoleMessage "Sending SIGTERM to Roxen process." 
            ./start --restart $flags 2>/dev/null 
            ConsoleMessage "Roxen restarted." 
        else 
            ConsoleMessage "Cannot find a Roxen installation in $roxenhome." 
        fi 
    } 
} 
 
status() 
{ 
    ConsoleMessage "Status of Roxen in $roxenhome..." 
    cd $roxenhome && { 
        if [ -x $roxenhome/start ]; then 
            if ./start --signal 0 $flags 2>/dev/null; then 
                ConsoleMessage "Roxen is running." 
                status=0 
                return 0; 
            fi 
            ConsoleMessage "Roxen is not running." 
        else 
            ConsoleMessage "Cannot find a Roxen installation in $roxenhome." 
        fi 
    } 
} 
 
debug() 
{ 
    ConsoleMessage "Debugging Roxen in $roxenhome..." 
    cd $roxenhome && { 
        if [ -x $roxenhome/start ]; then 
            if ./start --signal QUIT $flags 2>/dev/null; then 
                ConsoleMessage "Roxen process found. Consult debug log for output." 
                return 0; 
            fi 
            ConsoleMessage "Roxen doesn't seem to be running." 
        else 
            ConsoleMessage "Cannot find a Roxen installation in $roxenhome." 
        fi 
    } 
} 
 
dorunservice() 
{ 
    if [ $1 = "status" ] ; then 
        status=1 
        status 
    elif [ $1 = "debug" ] ; then 
        debug 
    else 
        RunService "$1" 
    fi 
} 
 
getvariables() 
{ 
    ConsoleMessage "Configuration dir: $1" 
    test -r $1/_startparams && source $1/_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 
                ConsoleMessage "No Roxen dir found, exiting!" 
                exit 1 
        fi 
        ConsoleMessage "Warning: $oldroxenhome does not exist, trying $roxenhome instead." 
    fi 
    test -r $1/_environment && source $1/_environment 
    if [ ! -d `dirname $ROXEN_PID_FILE` ] ; then 
        ConsoleMessage "`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 [ -d $roxenconfdir ] ; then 
    if [ -z $useconfig ] ; then 
        for f in $roxenconfdir/* ; do 
            getvariables $f 
            dorunservice $1 
        done 
    else 
        getvariables $roxenconfdir/$2 
        dorunservice $1 
    fi 
else 
    dorunservice $1 
fi 
 
if [ $1 = "status" ] ; then 
        exit $status 
fi