aboutsummaryrefslogtreecommitdiffstats
path: root/ncomp-cdap-adaptor/src/main/server-gen/bin/cdap-adaptor-controller
blob: 780012af6020075b66f6ab27714f3ee6c733c015 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/bash 

# setup env if needed. java 6 required
## JAVA_HOME=
  
############################## DO NOT EDIT BELOW ##########################

SNAME="Cdap Controller"
PNAME=cdap-adaptor-controller
CLASS=org.openecomp.ncomp.servers.cdap.CdapCdapAdaptorServer

############################## COMMON BELOW ##########################

check_status ()
{
    if [ -f "${_PIDFILE}" ]; then
        _PID=`cat "${_PIDFILE}"`
        check_status_of_pid $_PID
    else
        _STATUS="$SNAME (no pidfile) is NOT running"
        _RUNNING=0
    fi
}


check_status_of_pid ()
{
    if [ -n "$1" ] && kill -0 $1 2>/dev/null ; then
        _STATUS="$SNAME (pid $1) is running"
        _RUNNING=1
    else
        _STATUS="$SNAME (pid $1) is NOT running"
        _RUNNING=0
    fi
}


check_status_of_pid ()
{
    if [ -n "$1" ] && kill -0 $1 2>/dev/null ; then
        _STATUS="$SNAME (pid $1) is running"
        _RUNNING=1
    else
        _STATUS="$SNAME (pid $1) is NOT running"
        _RUNNING=0
    fi
}

remove_pid_file ()
{
   if [ -f "${_PIDFILE}" ]; then
      rm "${_PIDFILE}"
   fi
}


_DIR=`dirname "$0"`
_DIR=`dirname "$_DIR"`

_PIDFILE=$_DIR/PID

CMD=$1
shift

check_status

CP=$(find $_DIR/lib/*/* -name \*.jar 2>/dev/null | xargs -I X printf ":%s" X)

JVMARGS=$(grep 'server.jvmargs' $_DIR/config/cdap.properties | sed -e 's/.*=//')

case $CMD in 
  status)
    echo $_STATUS
    exit 0
    ;;
  console)
    $GROOVY_HOME/bin/groovysh -cp $_DIR/config:$_DIR/lib:$_DIR/lib/\*:$CP 
    ;;
  run)
    $JAVA_HOME/bin/java -cp $_DIR/config:$_DIR/lib:$_DIR/lib/\*:$CP "$@"
    ;;
  groovy)
    $GROOVY_HOME/bin/groovy -cp $_DIR/config:$_DIR/lib:$_DIR/lib/\*:$CP "$@"
    ;;
   start)
    if [ "$_RUNNING" = "1" ]; then
      echo $_STATUS
      exit 0
    fi
    mkdir -p $_DIR/logs
    if [ -e $_DIR/logs/$PNAME.out.1 ]; then mv $_DIR/logs/$PNAME.out.1 $_DIR/logs/$PNAME.out.2; fi
    if [ -e $_DIR/logs/$PNAME.err.1 ]; then mv $_DIR/logs/$PNAME.err.1 $_DIR/logs/$PNAME.err.2; fi
    if [ -e $_DIR/logs/$PNAME.out ]; then mv $_DIR/logs/$PNAME.out $_DIR/logs/$PNAME.out.1; fi
    if [ -e $_DIR/logs/$PNAME.err ]; then mv $_DIR/logs/$PNAME.err $_DIR/logs/$PNAME.err.1; fi

    nohup $JAVA_HOME/bin/java $JVMARGS -cp $_DIR/config:$_DIR/lib:$_DIR/lib/\*:$CP "$@" $CLASS >> $_DIR/logs/$PNAME.out 2>> $_DIR/logs/$PNAME.err  &

    _PID=$!
    echo $_PID > $_PIDFILE
    sleep 5
    check_status
    echo $_STATUS
    if [ "$_RUNNING" = "1" ]; then
       exit 0
    else
       echo "Failed to start - make sure the $SNAME is fully configured properly"
       exit 1
    fi
    ;;
  stop)
    if [ "$_RUNNING" = "0" ]; then
       echo $_STATUS
       remove_pid_file
       exit 0
    fi
    echo "Stopping $SNAME..."
    _PID_TO_KILL=$_PID;
    echo "$SNAME (pid=${_PID_TO_KILL}) is stopping..."
    kill -TERM $_PID_TO_KILL
    sleep 5
    check_status_of_pid $_PID_TO_KILL
    if [ "$_RUNNING" = "1" ]; then
       kill -TERM $_PID_TO_KILL
    fi
    while [ "$_RUNNING" = "1" ]; do
       sleep 2
       check_status_of_pid $_PID_TO_KILL
    done
    remove_pid_file
    echo "$SNAME has stopped."
    exit 0
    ;;
  *)
    echo "$0 start|stop"
    ;;
esac