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