nxhttpd traces removed
[public/netxms.git] / contrib / installBinaryAgent.sh
1 #!/bin/sh
2
3 # $Id$
4
5 # Copyright (c) 2007, NetXMS Team
6 #
7 # All rights reserved.
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
10 # are met:
11 #
12 # * Redistributions of source code must retain the above copyright notice,
13 # this list of conditions and the following disclaimer.
14 # * Redistributions in binary form must reproduce the above copyright notice,
15 # this list of conditions and the following disclaimer in the documentation
16 # and/or other materials provided with the distribution.
17 # * Neither the name of the <ORGANIZATION> nor the names of its contributors
18 # may be used to endorse or promote products derived from this software
19 # without specific prior written permission.
20
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33 prefix=/opt/netxms
34 config=/etc/nxagentd.conf
35 log=/tmp/nxagentbinupdate.log
36 platform=`uname -s`
37
38 ###############################################################################
39 #
40 # Main code
41 #
42
43 # process args
44 while test "x$1" != "x"; do
45 name=`echo $1|cut -d= -f1`
46 val=`echo $1|cut -d= -f2`
47 eval $name=$val
48 shift
49 done
50
51 cd `dirname $0`
52 name=`ls nxagent-*.tar.gz 2>/dev/null|sed s',\.tar\.gz$,,'`
53 if test "x$name" = "x"; then
54 echo invalid package >>$log
55 exit 1
56 fi
57
58 rm -rf tmp
59 mkdir tmp && cd tmp
60
61 gzip -dc ../$name.tar.gz | tar xf - 2>/dev/null
62 if test $? != 0; then
63 echo Unable to unpack >>$log
64 exit 2
65 fi
66
67 pids=`ps -e | grep nxagentd | grep -v grep | awk '{ print $1; }'`
68
69 if test "x$pids" != "x"; then
70 # ask nxagentd gently
71 kill $pids >>$log 2>&1
72 # wait a few seconds and smash it down
73 sleep 15 && kill -9 $pids >>$log 2>&1
74 fi
75
76 # install new files
77 mkdir $prefix 2>/dev/null
78 if test "x$platform" = "xAIX"; then
79 slibclean
80 cp -f -R * $prefix/ 2>>$log
81 else
82 cp -R * $prefix/ 2>>$log
83 fi
84 if test $? != 0; then
85 echo unable to copy new files to $prefix >>$log
86 exit 3
87 fi
88
89 # show config
90 echo "config ($config):" >>$log
91 cat $config >>$log 2>&1
92 echo "---------------" >>$log
93
94 # and restart
95 echo "Starting agent: $prefix/bin/nxagentd -d -c $config" >>$log
96 $prefix/bin/nxagentd -d -c $config >>$log 2>&1
97 ret=$?
98 if test $ret != 0; then
99 echo nxagentd not started \($ret\) >>$log
100 exit 5
101 fi
102 rm -f $log.tmp