nxhttpd traces removed
[public/netxms.git] / contrib / installAgent.sh
CommitLineData
ed73635e
AK
1#!/bin/sh
2
bdeffcb7
AK
3prefix=/opt/netxms
4config=/etc/nxagentd.conf
5e43ae16 5log=/tmp/nxagentupdate.log
bdeffcb7 6#prefix=/usr/local
ed73635e
AK
7configureAdd=
8
ed73635e
AK
9###############################################################################
10#
11# Main code
12#
13
bdeffcb7
AK
14# process args
15while [ "x"$1 != "x" ]; do
02d6e024
AK
16 name=`echo $1|cut -d= -f1`
17 val=`echo $1|cut -d= -f2`
dfa81f4b
VK
18 if [ "x$name" = "xopt" ]; then
19 configureAdd="$configureAdd $val"
20 else
21 eval $name=$val
22 fi
bdeffcb7
AK
23 shift
24done
25
9523ff5c 26make=`which gmake`
3e80aa9c
AK
27if [ $? = 0 ]; then
28 echo $make | grep "no gmake in " >/dev/null && make=make
29else
30 make=make
31fi
9523ff5c 32
ed73635e 33case `uname -s` in
861fb447 34 SunOS)
78821e2f
AK
35 KILLALL() {
36 pkill $*
37 }
ed73635e 38 ;;
78821e2f
AK
39 AIX|HP-UX)
40 KILLALL() {
41 pids=`/usr/bin/ps -ef | grep $2 | grep -v grep | awk '{ print $2 }'`
42 [ ! -z "$pids" ] && kill $1 $pids
43 }
ed73635e 44 ;;
e1ca00b2
AK
45 *)
46 KILLALL() {
47 killall $*
48 }
49 ;;
ed73635e
AK
50esac
51
52cd `dirname $0`
53name=`ls netxms-*.tar.gz 2>/dev/null|sed s',\.tar\.gz$,,'`
54if [ "x$name" = "x" ]; then
c0b41956 55 echo invalid package >>$log
ed73635e
AK
56 exit 1
57fi
58
3e80aa9c 59gzip -dc $name.tar.gz | tar xf - 2>/dev/null
ed73635e 60if [ $? != 0 ]; then
38656df9 61 echo Unable to unpack >>$log
ed73635e
AK
62 exit 2
63fi
64cd $name
65if [ $? != 0 ]; then
38656df9 66 echo Unable to change working dir >>$log
ed73635e
AK
67 exit 3
68fi
69
74dd9f19 70# ask nxagentd gently
78821e2f 71KILLALL -15 nxagentd >>$log 2>&1
74dd9f19 72# wait a few seconds and smash it down
78821e2f 73sleep 15 && KILLALL -9 nxagentd >>$log 2>&1
74dd9f19 74
ed73635e 75# do configure
c0b41956 76./configure --prefix=$prefix --with-agent $configureAdd >>$log 2>&1
78821e2f 77 if [ $? != 0 ]; then
c0b41956 78 echo configure failed, restarting old agent >>$log
78821e2f
AK
79 # Try to restart existing agent
80 $prefix/bin/nxagentd -d -c $config >>$log 2>&1
ed73635e
AK
81 exit 4
82fi
83
84# build
c0b41956 85$make >>$log 2>&1
ed73635e 86if [ $? != 0 ]; then
6e320944 87 echo build failed, restarting old agent >>$log
78821e2f
AK
88 # Try to restart existing agent
89 $prefix/bin/nxagentd -d -c $config >>$log 2>&1
ed73635e
AK
90 exit 4
91fi
92
74dd9f19 93# now we can install it...
c0b41956 94$make install >>$log 2>&1
ed73635e 95if [ $? != 0 ]; then
c0b41956 96 echo install failed, restarting old agent >>$log
78821e2f
AK
97 # Try to restart existing agent
98 $prefix/bin/nxagentd -d -c $config >>$log 2>&1
ed73635e
AK
99 exit 5
100fi
101
62e9320f 102# show config
c0b41956
AK
103echo "config ($config):" >>$log
104cat $config >>$log 2>&1
105echo "---------------" >>$log
62e9320f 106
ed73635e 107# and restart
c0b41956
AK
108echo "Starting agent: $prefix/bin/nxagentd -d -c $config" >>$log
109$prefix/bin/nxagentd -d -c $config >>$log 2>&1
62e9320f
AK
110ret=$?
111if [ $ret != 0 ]; then
c0b41956 112 echo nxagentd not started \($ret\) >>$log
ed73635e
AK
113 exit 5
114fi
62e9320f 115rm -f $log.tmp