Add License to VES library
[demo.git] / boot / dcae_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="./dcae_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 }
46
47 case "$1" in
48     start)
49     if is_running; then
50         echo "Already started"
51     else
52         echo "Starting $name"
53         cd "$dir"
54         if [ -z "$user" ]; then
55             sudo $cmd >> "$stdout_log" 2>> "$stderr_log" &
56         else
57             sudo -u "$user" $cmd >> "$stdout_log" 2>> "$stderr_log" &
58         fi
59         echo $! > "$pid_file"
60         if ! is_running; then
61             echo "Unable to start, see $stdout_log and $stderr_log"
62             exit 1
63         fi
64     fi
65     ;;
66     stop)
67     if is_running; then
68         echo -n "Stopping $name.."
69         kill `get_pid`
70         for i in {1..10}
71         do
72             if ! is_running; then
73                 break
74             fi
75
76             echo -n "."
77             sleep 1
78         done
79         echo
80
81         if is_running; then
82             echo "Not stopped; may still be shutting down or shutdown may have failed"
83             exit 1
84         else
85             echo "Stopped"
86             if [ -f "$pid_file" ]; then
87                 rm "$pid_file"
88             fi
89         fi
90     else
91         echo "Not running"
92     fi
93     ;;
94     restart)
95     $0 stop
96     if is_running; then
97         echo "Unable to stop, will not attempt to start"
98         exit 1
99     fi
100     $0 start
101     ;;
102     status)
103     if is_running; then
104         echo "Running"
105     else
106         echo "Stopped"
107         exit 1
108     fi
109     ;;
110     *)
111     echo "Usage: $0 {start|stop|restart|status}"
112     exit 1
113     ;;
114 esac
115
116 exit 0