updated on Thu Jan 12 04:00:44 UTC 2012
[aur-mirror.git] / mindtouch / init-script
blob031a98489571ce6d126b9e5110f8cb8aeecd90da
1 #!/bin/bash
3 . /etc/rc.conf
4 . /etc/rc.d/functions
6 DEKIHOST_CONF="/etc/webapps/mindtouch/mindtouch.host.conf"
7 DEKIWIKI_USER="http"
9 if [ ! -f $DEKIHOST_CONF ]; then
10 echo "$DEKIHOST_CONF does not exist"
11 exit 1
14 . $DEKIHOST_CONF
16 # set default values if not specified in $DEKIHOST_CONF
18 if [ ! -f "$MONO" ]; then
19 echo "Please specify the full path to your mono binary"
20 exit 1
23 if [ ! -d "$BIN_DIR" ]; then
24 echo "Please specify the path to your MindTouch bin directory"
25 exit 1
28 if [ -z "$APIKEY" ]; then
29 echo "Please specify your APIKEY"
30 exit 1
33 if [ -z "$PATH_PREFIX" ]; then
34 PATH_PREFIX="@api"
37 if [ -z "$HTTP_PORT" ]; then
38 HTTP_PORT="8081"
41 if [ -z "$IP" ]; then
42 IP="localhost"
45 if [ -z "$HOST_EXE" ]; then
46 HOST_EXE="$BIN_DIR/mindtouch.host.exe"
49 if [ -z "$SCRIPT" ]; then
50 SCRIPT="/etc/dekiwiki/mindtouch.deki.startup.xml"
53 if [ -z "$NOTTY" ]; then
54 NOTTY="notty"
57 if [ -z "$CONNECT_LIMIT" ]; then
58 CONNECT_LIMIT="-5"
61 if [ -z "$LOGDIR" ]; then
62 LOGDIR="/var/www/dekiwiki"
65 if [ -z "$LOGFILE" ]; then
66 LOGFILE="$LOGDIR/deki-api.log"
69 if [ ! -z "$GUID" ]; then
70 GUID="guid $GUID"
73 if [ ! -z "$STORAGEDIR" ]; then
74 STORAGEDIR="storage-dir $STORAGEDIR"
77 pidof_dekiwiki() {
78 # we grep on assembly name and port in case multiple mono processes are running
79 echo $(ps -U $DEKIWIKI_USER -o pid,cmd | grep mindtouch.host.exe | grep $HTTP_PORT | awk '{print $1}')
82 stop() {
83 PID=$(pidof_dekiwiki)
84 stat_busy "Stopping MindTouch API"
85 if [ -z "$PID" ]; then
86 echo -n "MindTouch is not running."
87 stat_fail
88 exit 1
89 else
90 # attempt to shut down gracefully using curl
91 curl -m 10 -s -d "" "http://$IP:$HTTP_PORT/host/?apikey=$APIKEY&dream.in.verb=DELETE"
92 sleep 3
94 # if the host didn't shut down properly then kill it
95 PID=$(pidof_dekiwiki)
96 if [ -n "$PID" ]; then
97 kill $PID
98 sleep 3
99 # if it still didn't go away, fail
100 PID=$(pidof_dekiwiki)
101 if [ -n "$PID" ]; then
102 stat_fail
103 exit 1
107 rm -f /var/run/mindtouch.pid
108 rm_daemon mindtouch
109 stat_done
113 start() {
114 stat_busy "Starting MindTouch API"
115 if [ ! -d $LOGDIR ]; then
116 mkdir $LOGDIR
117 chown $DEKIWIKI_USER $LOGDIR
119 # see if the process is already running
120 PID=$(pidof_dekiwiki)
121 if [ -n "$PID" ]; then
122 echo -n "MindTouch is already running: $PID"
123 stat_fail
124 exit 1;
126 MONO_ARGS="$HOST_EXE apikey $APIKEY script $SCRIPT path-prefix $PATH_PREFIX http-port $HTTP_PORT ip $IP connect-limit $CONNECT_LIMIT $NOTTY $GUID $STORAGEDIR"
127 su -s /bin/bash -c "exec $MONO $MONO_ARGS " $DEKIWIKI_USER >> $LOGFILE 2>&1 &
128 sleep 3
130 PID=$(pidof_dekiwiki)
131 if [ -z "$PID" ]; then
132 stat_fail
133 exit 1
134 else
135 echo "$PID" > /var/run/mindtouch.pid
136 add_daemon mindtouch
137 stat_done
142 case "$1" in
143 start)
144 start
146 stop)
147 stop
149 restart)
150 stop
151 start
154 echo "Usage: $0 {start|stop|restart}" >&2
155 exit 1
156 esac
158 exit 0