Improve the way to deploy onap via proxy
[demo.git] / boot / dcae2_serv.sh
1 #!/bin/sh
2 #############################################################################
3 #
4 # Copyright (c) 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 ### BEGIN INIT INFO
20 # Provides: dcaegen2-bootstrap
21 # Required-Start: $remote_fs $syslog
22 # Required-Stop: $remote_fs $syslog
23 # Default-Start: 2 3 4 5
24 # Default-Stop: 0 1 6
25 # Short-Description: Start daemon at boot time
26 # Description: Enable service provided by daemon.
27 ### END INIT INFO
28 HTTP_PROXY=$(cat /opt/config/http_proxy.txt)
29 HTTPS_PROXY=$(cat /opt/config/https_proxy.txt)
30
31 if [ $HTTP_PROXY != " " ]
32 then
33     export http_proxy=$HTTP_PROXY
34     export https_proxy=$HTTPS_PROXY
35 fi
36
37 dir="/opt"
38 cmd="./dcae2_vm_init.sh"
39 user="root"
40
41 name=$(basename "$0")
42 pid_file="/var/run/$name.pid"
43 stdout_log="/var/log/$name.log"
44 stderr_log="/var/log/$name.err"
45
46 get_pid() {
47     cat "$pid_file"
48 }
49
50 is_running() {
51     CID="$(docker ps | grep 'org.onap.dcaegen2.deployments.bootstrap')"
52     [ ! -z "$CID" ]
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         CID=$(docker ps | grep 'nginx' | awk '{ print $1 }')
79         sudo docker stop "$CID"
80
81         CID=$(docker ps | grep 'org.onap.dcaegen2.deployments.bootstrap' | awk '{ print $1 }')
82         docker exec -it "$CID" ./teardown.sh
83         for i in {1..10}
84         do
85             if ! is_running; then
86                 break
87             fi
88
89             echo -n "."
90             sleep 1
91         done
92         echo
93
94         if is_running; then
95             echo "Not stopped; may still be shutting down or shutdown may have failed"
96             exit 1
97         else
98             echo "Stopped"
99             if [ -f "$pid_file" ]; then
100                 rm "$pid_file"
101             fi
102         fi
103     else
104         echo "Not running"
105     fi
106     ;;
107     restart)
108     $0 stop
109     if is_running; then
110         echo "Unable to stop, will not attempt to start"
111         exit 1
112     fi
113     $0 start
114     ;;
115     status)
116     if is_running; then
117         echo "Running"
118     else
119         echo "Stopped"
120         exit 1
121     fi
122     ;;
123     *)
124     echo "Usage: $0 {start|stop|restart|status}"
125     exit 1
126     ;;
127 esac
128
129 exit 0