Remove demo, testuite/properties repos in robot VM
[demo.git] / boot / sms_serv.sh
1 #!/bin/sh
2 ### BEGIN INIT INFO
3 # Provides:
4 # Required-Start:    $remote_fs $syslog
5 # Required-Stop:     $remote_fs $syslog
6 # Default-Start:     2 3 4 5
7 # Default-Stop:      0 1 6
8 # Short-Description: Start daemon at boot time
9 # Description:       Enable service provided by daemon.
10 ### END INIT INFO
11 HTTP_PROXY=$(cat /opt/config/http_proxy.txt)
12 HTTPS_PROXY=$(cat /opt/config/https_proxy.txt)
13
14 if [ $HTTP_PROXY != "no_proxy" ]
15 then
16     export http_proxy=$HTTP_PROXY
17     export https_proxy=$HTTPS_PROXY
18 fi
19
20 dir="/opt"
21 cmd="./sms_vm_init.sh"
22 user="root"
23
24 name=`basename $0`
25 pid_file="/var/run/$name.pid"
26 stdout_log="/var/log/$name.log"
27 stderr_log="/var/log/$name.err"
28
29 get_pid() {
30     cat "$pid_file"
31 }
32
33 is_running() {
34     [ -f "$pid_file" ] && ps `get_pid` > /dev/null 2>&1
35 }
36
37 case "$1" in
38     start)
39     if is_running; then
40         echo "Already started"
41     else
42         echo "Starting $name"
43         cd "$dir"
44         if [ -z "$user" ]; then
45             sudo $cmd >> "$stdout_log" 2>> "$stderr_log" &
46         else
47             sudo -u "$user" $cmd >> "$stdout_log" 2>> "$stderr_log" &
48         fi
49         echo $! > "$pid_file"
50         if ! is_running; then
51             echo "Unable to start, see $stdout_log and $stderr_log"
52             exit 1
53         fi
54     fi
55     ;;
56     stop)
57     if is_running; then
58         echo -n "Stopping $name.."
59         kill `get_pid`
60         for i in {1..10}
61         do
62             if ! is_running; then
63                 break
64             fi
65
66             echo -n "."
67             sleep 1
68         done
69         echo
70
71         if is_running; then
72             echo "Not stopped; may still be shutting down or shutdown may have failed"
73             exit 1
74         else
75             echo "Stopped"
76             if [ -f "$pid_file" ]; then
77                 rm "$pid_file"
78             fi
79         fi
80     else
81         echo "Not running"
82     fi
83     ;;
84     restart)
85     $0 stop
86     if is_running; then
87         echo "Unable to stop, will not attempt to start"
88         exit 1
89     fi
90     $0 start
91     ;;
92     status)
93     if is_running; then
94         echo "Running"
95     else
96         echo "Stopped"
97         exit 1
98     fi
99     ;;
100     *)
101     echo "Usage: $0 {start|stop|restart|status}"
102     exit 1
103     ;;
104 esac
105
106 exit 0