Merge "Remove unnecessary install of JDK"
[demo.git] / boot / mr_serv.sh
1
2 #############################################################################
3 #
4 # Copyright © 2017 AT&T Intellectual Property. All rights reserved.
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #        http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17 #############################################################################
18
19 #!/bin/sh
20 ### BEGIN INIT INFO
21 # Provides:
22 # Required-Start:    $remote_fs $syslog
23 # Required-Stop:     $remote_fs $syslog
24 # Default-Start:     2 3 4 5
25 # Default-Stop:      0 1 6
26 # Short-Description: Start daemon at boot time
27 # Description:       Enable service provided by daemon.
28 ### END INIT INFO
29 HTTP_PROXY=$(cat /opt/config/http_proxy.txt)
30 HTTPS_PROXY=$(cat /opt/config/https_proxy.txt)
31
32 if [ $HTTP_PROXY != "no_proxy" ]
33 then
34     export http_proxy=$HTTP_PROXY
35     export https_proxy=$HTTPS_PROXY
36 fi
37
38 dir="/opt"
39 cmd="./mr_vm_init.sh"
40 user="root"
41
42 name=`basename $0`
43 pid_file="/var/run/$name.pid"
44 stdout_log="/var/log/$name.log"
45 stderr_log="/var/log/$name.err"
46
47 get_pid() {
48     cat "$pid_file"
49 }
50
51 is_running() {
52     [ -f "$pid_file" ] && ps `get_pid` > /dev/null 2>&1
53 }
54
55 case "$1" in
56     start)
57     if is_running; then
58         echo "Already started"
59     else
60         echo "Starting $name"
61         cd "$dir"
62         if [ -z "$user" ]; then
63             sudo $cmd >> "$stdout_log" 2>> "$stderr_log" &
64         else
65             sudo -u "$user" $cmd >> "$stdout_log" 2>> "$stderr_log" &
66         fi
67         echo $! > "$pid_file"
68         if ! is_running; then
69             echo "Unable to start, see $stdout_log and $stderr_log"
70             exit 1
71         fi
72     fi
73     ;;
74     stop)
75     if is_running; then
76         echo -n "Stopping $name.."
77         kill `get_pid`
78         for i in {1..10}
79         do
80             if ! is_running; then
81                 break
82             fi
83
84             echo -n "."
85             sleep 1
86         done
87         echo
88
89         if is_running; then
90             echo "Not stopped; may still be shutting down or shutdown may have failed"
91             exit 1
92         else
93             echo "Stopped"
94             if [ -f "$pid_file" ]; then
95                 rm "$pid_file"
96             fi
97         fi
98     else
99         echo "Not running"
100     fi
101     ;;
102     restart)
103     $0 stop
104     if is_running; then
105         echo "Unable to stop, will not attempt to start"
106         exit 1
107     fi
108     $0 start
109     ;;
110     status)
111     if is_running; then
112         echo "Running"
113     else
114         echo "Stopped"
115         exit 1
116     fi
117     ;;
118     *)
119     echo "Usage: $0 {start|stop|restart|status}"
120     exit 1
121     ;;
122 esac
123
124 exit 0