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