Update dcae2 vm_init and intsall scripts
[demo.git] / boot / dcae2_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
30 dir="/opt"
31 cmd="./dcae2_vm_init.sh"
32 user="root"
33
34 name=`basename $0`
35 pid_file="/var/run/$name.pid"
36 stdout_log="/var/log/$name.log"
37 stderr_log="/var/log/$name.err"
38
39 get_pid() {
40     cat "$pid_file"
41 }
42
43 is_running() {
44     #[ -f "$pid_file" ] && ps `get_pid` > /dev/null 2>&1
45     [ ! -z $(docker ps | grep 'org.onap.dcaegen2.deployments.bootstrap') ]
46 }
47
48 case "$1" in
49     start)
50     if is_running; then
51         echo "Already started"
52     else
53         echo "Starting $name"
54         cd "$dir"
55         if [ -z "$user" ]; then
56             sudo $cmd >> "$stdout_log" 2>> "$stderr_log" &
57         else
58             sudo -u "$user" $cmd >> "$stdout_log" 2>> "$stderr_log" &
59         fi
60         echo $! > "$pid_file"
61         if ! is_running; then
62             echo "Unable to start, see $stdout_log and $stderr_log"
63             exit 1
64         fi
65     fi
66     ;;
67     stop)
68     if is_running; then
69         echo -n "Stopping $name.."
70         kill `get_pid`
71         CID=$(docker ps | grep 'org.onap.dcaegen2.deployments.bootstrap' | awk '{ print $1 }')
72         docker exec -it $CID ./teardown.sh
73         for i in {1..10}
74         do
75             if ! is_running; then
76                 break
77             fi
78
79             echo -n "."
80             sleep 1
81         done
82         echo
83
84         if is_running; then
85             echo "Not stopped; may still be shutting down or shutdown may have failed"
86             exit 1
87         else
88             echo "Stopped"
89             if [ -f "$pid_file" ]; then
90                 rm "$pid_file"
91             fi
92         fi
93     else
94         echo "Not running"
95     fi
96     ;;
97     restart)
98     $0 stop
99     if is_running; then
100         echo "Unable to stop, will not attempt to start"
101         exit 1
102     fi
103     $0 start
104     ;;
105     status)
106     if is_running; then
107         echo "Running"
108     else
109         echo "Stopped"
110         exit 1
111     fi
112     ;;
113     *)
114     echo "Usage: $0 {start|stop|restart|status}"
115     exit 1
116     ;;
117 esac
118
119 exit 0