Improve the way to deploy onap via proxy
[demo.git] / boot / aaf_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
12 HTTP_PROXY=$(cat /opt/config/http_proxy.txt)
13 HTTPS_PROXY=$(cat /opt/config/https_proxy.txt)
14
15 if [ $HTTP_PROXY != " " ]
16 then
17     export http_proxy=$HTTP_PROXY
18     export https_proxy=$HTTPS_PROXY
19 fi
20
21 dir="/opt"
22 cmd="./aaf_vm_init.sh"
23 user="root"
24
25 name=`basename $0`
26 pid_file="/var/run/$name.pid"
27 stdout_log="/var/log/$name.log"
28 stderr_log="/var/log/$name.err"
29
30 get_pid() {
31     cat "$pid_file"
32 }
33
34 is_running() {
35     [ -f "$pid_file" ] && ps `get_pid` > /dev/null 2>&1
36 }
37
38 case "$1" in
39     start)
40     if is_running; then
41         echo "Already started"
42     else
43         echo "Starting $name"
44         cd "$dir"
45         if [ -z "$user" ]; then
46             sudo $cmd >> "$stdout_log" 2>> "$stderr_log" &
47         else
48             sudo -u "$user" $cmd >> "$stdout_log" 2>> "$stderr_log" &
49         fi
50         echo $! > "$pid_file"
51         if ! is_running; then
52             echo "Unable to start, see $stdout_log and $stderr_log"
53             exit 1
54         fi
55     fi
56     ;;
57     stop)
58     if is_running; then
59         echo -n "Stopping $name.."
60         kill `get_pid`
61         for i in {1..10}
62         do
63             if ! is_running; then
64                 break
65             fi
66
67             echo -n "."
68             sleep 1
69         done
70         echo
71
72         if is_running; then
73             echo "Not stopped; may still be shutting down or shutdown may have failed"
74             exit 1
75         else
76             echo "Stopped"
77             if [ -f "$pid_file" ]; then
78                 rm "$pid_file"
79             fi
80         fi
81     else
82         echo "Not running"
83     fi
84     ;;
85     restart)
86     $0 stop
87     if is_running; then
88         echo "Unable to stop, will not attempt to start"
89         exit 1
90     fi
91     $0 start
92     ;;
93     status)
94     if is_running; then
95         echo "Running"
96     else
97         echo "Stopped"
98         exit 1
99     fi
100     ;;
101     *)
102     echo "Usage: $0 {start|stop|restart|status}"
103     exit 1
104     ;;
105 esac
106
107 exit 0