root/tools/routingservice/trunk/routingservice.sh

Revision 288, 2.3 KB (checked in by daniel, 20 months ago)

startup script works from other directories

  • Property svn:executable set to *
Line 
1#!/bin/sh
2
3#
4# A simple startup script
5#
6SCRIPT=$(readlink -f $0)
7cd `dirname $SCRIPT`
8
9# Run this program
10PROGRAM="java -cp .:jp/co/orkney/restlet:lib/antlrworks-1.1.3.jar:lib/org.restlet.ext.json_2.0.jar:lib/com.noelios.restlet.ext.simple_3.1.jar:lib/org.restlet.jar:lib/com.noelios.restlet.jar:lib/org.simpleframework.jar:lib/jdom.jar:lib/postgresql-8.1-413.jdbc3.jar:lib/org.json.jar:lib/commons-dbcp-1.2.2.jar:lib/commons-pool-1.4.jar:lib/com.noelios.restlet.ext.jdbc_3.0.jar jp.co.orkney.restlet.WebRouting"
11
12# In case "identifier" parameter is not set
13if [ $2 ]
14then
15        pidfile="log/restlet-$2.pid"
16else
17        pidfile="log/restlet-wrs.pid"
18fi
19
20# What should the service do?
21case $1 in
22        start)
23
24echo "
25Service starting ..."
26
27                if [ -e "$pidfile" ]
28                then
29
30echo "Service is already running!"
31echo "Do nothing ...
32[$pidfile]
33
34"
35                else
36                        $PROGRAM &
37                        PID=$!
38                        echo $PID > "$pidfile"
39
40echo "Service started!
41[$pidfile|$PID]
42
43"
44                fi             
45        ;;
46       
47        restart)
48
49echo "
50Service restarting ..."
51
52                if [ -e "$pidfile" ]
53                then
54                        pid2kill=`cat $pidfile`
55                        kill -9 $pid2kill
56                        rm $pidfile
57
58echo "Service stopped!"
59
60                else
61
62echo "No running service found ... starting a new one!"
63
64                fi
65               
66                $PROGRAM &
67                PID=$!
68                echo $PID > "$pidfile"
69
70echo "Service started!
71[$pidfile|$PID]
72
73"
74        ;;
75       
76        stop)
77                if [ -e "$pidfile" ]
78                then
79                        pid2kill=`cat $pidfile`
80                        kill -9 $pid2kill
81                        rm $pidfile
82
83echo "
84Service stopped!
85[$pid2kill]
86
87"
88                else
89echo "
90No service found!
91
92"
93                fi
94        ;;
95
96
97        list)
98                # get current processes
99echo "
100Currently active WRS process(es):
101"
102
103ps afx | grep restlet
104
105echo "
106
107"
108        ;;
109       
110        debug)
111                # run the program as is
112echo "
113Service starting in DEBUG mode ...
114Type CTRL-C to stop the service.
115
116"
117                $PROGRAM
118        ;;
119       
120        help)
121echo "
122This is the Webrouting Service startup script
123
124Usage:
125        ./routingservice.sh {start|stop|restart|debug|list|help} [identifier]
126
127Commands:
128        start           Start the service
129        stop            Stop the service
130        restart         Stop and immediately start the service again
131        debug           Run the service in debug mode
132                        This will print log messages to the terminal window.
133        list            List currently active process(es)
134        help            Show the startup help
135
136Optional:
137        identifier      Run the service as a distinct process.
138
139"
140        ;;
141       
142        *)
143echo "
144Usage: ./routingservice.sh {start|stop|restart|debug|help}
145
146"
147        ;;
148esac
Note: See TracBrowser for help on using the browser.