Various fixes
[public/netxms.git] / contrib / installBinaryAgent.sh
1 #!/bin/sh
2
3 # $Id: installBinaryAgent.sh,v 1.2 2007-05-26 10:42:19 victor Exp $
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
37 ###############################################################################
38 #
39 # Main code
40 #
41
42 # process args
43 while [ "x"$1 != "x" ]; do
44 name=`echo $1|cut -d= -f1`
45 val=`echo $1|cut -d= -f2`
46 eval $name=$val
47 shift
48 done
49
50 cd `dirname $0`
51 name=`ls nxagent-*.tar.gz 2>/dev/null|sed s',\.tar\.gz$,,'`
52 if [ "x$name" = "x" ]; then
53 echo invalid package >>$log
54 exit 1
55 fi
56
57 rm -rf tmp
58 mkdir tmp && cd tmp
59
60 gzip -dc ../$name.tar.gz | tar xf - 2>/dev/null
61 if [ $? != 0 ]; then
62 echo Unable to unpack >>$log
63 exit 2
64 fi
65
66 pids=`ps -e | grep nxagentd | grep -v grep | awk '{ print $1; }'`
67
68 if [ "x$pids" != "x" ]; then
69 # ask nxagentd gently
70 kill $pids >>$log 2>&1
71 # wait a few seconds and smash it down
72 sleep 15 && kill -9 $pids >>$log 2>&1
73 fi
74
75 # install new files
76 mkdir $prefix 2>/dev/null
77 cp -R * $prefix/ 2>>$log
78 if [ $? != 0 ]; then
79 echo unable to copy new files to $prefix >>$log
80 exit 3
81 fi
82
83 # show config
84 echo "config ($config):" >>$log
85 cat $config >>$log 2>&1
86 echo "---------------" >>$log
87
88 # and restart
89 echo "Starting agent: $prefix/bin/nxagentd -d -c $config" >>$log
90 $prefix/bin/nxagentd -d -c $config >>$log 2>&1
91 ret=$?
92 if [ $ret != 0 ]; then
93 echo nxagentd not started \($ret\) >>$log
94 exit 5
95 fi
96 rm -f $log.tmp