projects
/
ossec-hids.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
new upstream release (3.3.0); modify package compatibility for Stretch
[ossec-hids.git]
/
src
/
init
/
ossec-client.sh
diff --git
a/src/init/ossec-client.sh
b/src/init/ossec-client.sh
index
e05d615
..
265d03f
100755
(executable)
--- a/
src/init/ossec-client.sh
+++ b/
src/init/ossec-client.sh
@@
-3,32
+3,28
@@
# or stopping ossec-hids
# Author: Daniel B. Cid <daniel.cid@gmail.com>
# or stopping ossec-hids
# Author: Daniel B. Cid <daniel.cid@gmail.com>
-
LOCAL=`dirname $0`;
cd ${LOCAL}
PWD=`pwd`
DIR=`dirname $PWD`;
LOCAL=`dirname $0`;
cd ${LOCAL}
PWD=`pwd`
DIR=`dirname $PWD`;
-### Do not modify bellow here ###
+
+### Do not modify below here ###
NAME="OSSEC HIDS"
NAME="OSSEC HIDS"
-VERSION="v2.3"
-AUTHOR="Trend Micro Inc."
+VERSION="v3.3.0"
DAEMONS="ossec-logcollector ossec-syscheckd ossec-agentd ossec-execd"
DAEMONS="ossec-logcollector ossec-syscheckd ossec-agentd ossec-execd"
+[ -f /etc/ossec-init.conf ] && . /etc/ossec-init.conf
## Locking for the start/stop
LOCK="${DIR}/var/start-script-lock"
LOCK_PID="${LOCK}/pid"
## Locking for the start/stop
LOCK="${DIR}/var/start-script-lock"
LOCK_PID="${LOCK}/pid"
-
# This number should be more than enough (even if it is
# started multiple times together). It will try for up
# to 10 attempts (or 10 seconds) to execute.
MAX_ITERATION="10"
# This number should be more than enough (even if it is
# started multiple times together). It will try for up
# to 10 attempts (or 10 seconds) to execute.
MAX_ITERATION="10"
-
-
-# Check pid
checkpid()
{
for i in ${DAEMONS}; do
checkpid()
{
for i in ${DAEMONS}; do
@@
-37,24
+33,21
@@
checkpid()
if [ ! $? = 0 ]; then
echo "Deleting PID file '${DIR}/var/run/${i}-${j}.pid' not used..."
rm ${DIR}/var/run/${i}-${j}.pid
if [ ! $? = 0 ]; then
echo "Deleting PID file '${DIR}/var/run/${i}-${j}.pid' not used..."
rm ${DIR}/var/run/${i}-${j}.pid
- fi
- done
- done
+ fi
+ done
+ done
}
}
-
-
-# Lock function
lock()
{
i=0;
lock()
{
i=0;
-
+
# Providing a lock.
while [ 1 ]; do
mkdir ${LOCK} > /dev/null 2>&1
MSL=$?
if [ "${MSL}" = "0" ]; then
# Providing a lock.
while [ 1 ]; do
mkdir ${LOCK} > /dev/null 2>&1
MSL=$?
if [ "${MSL}" = "0" ]; then
- # Lock aquired (setting the pid)
+ # Lock acquired (setting the pid)
echo "$$" > ${LOCK_PID}
return;
fi
echo "$$" > ${LOCK_PID}
return;
fi
@@
-68,7
+61,7
@@
lock()
if [ ! $? = 0 ]; then
# Pid is not present.
i=`expr $i + 1`;
if [ ! $? = 0 ]; then
# Pid is not present.
i=`expr $i + 1`;
- fi
+ fi
# We tried 10 times to acquire the lock.
if [ "$i" = "${MAX_ITERATION}" ]; then
# We tried 10 times to acquire the lock.
if [ "$i" = "${MAX_ITERATION}" ]; then
@@
-81,72
+74,71
@@
lock()
done
}
done
}
-
-# Unlock function
unlock()
{
rm -rf ${LOCK}
}
unlock()
{
rm -rf ${LOCK}
}
-
-# Help message
help()
{
# Help message
help()
{
# Help message
- echo "Usage: $0 {start|stop|restart|status}";
+ echo "Usage: $0 {start|stop|reload|restart|status}";
exit 1;
}
exit 1;
}
-
-# Status function
status()
{
status()
{
+ RETVAL=0
for i in ${DAEMONS}; do
pstatus ${i};
if [ $? = 0 ]; then
for i in ${DAEMONS}; do
pstatus ${i};
if [ $? = 0 ]; then
+ RETVAL=1
echo "${i} not running..."
else
echo "${i} is running..."
fi
echo "${i} not running..."
else
echo "${i} is running..."
fi
- done
+ done
+ exit $RETVAL
}
}
-
-# Start function
-start()
+testconfig()
{
{
- SDAEMONS="ossec-execd ossec-agentd ossec-logcollector ossec-syscheckd"
-
- echo "Starting $NAME $VERSION (by $AUTHOR)..."
- lock;
- checkpid;
-
- # We first loop to check the config.
+ # We first loop to check the config.
for i in ${SDAEMONS}; do
${DIR}/bin/${i} -t;
if [ $? != 0 ]; then
echo "${i}: Configuration error. Exiting"
unlock;
exit 1;
for i in ${SDAEMONS}; do
${DIR}/bin/${i} -t;
if [ $? != 0 ]; then
echo "${i}: Configuration error. Exiting"
unlock;
exit 1;
- fi
+ fi
done
done
-
+}
+
+# Start function
+start()
+{
+ SDAEMONS="ossec-execd ossec-agentd ossec-logcollector ossec-syscheckd"
+
+ echo "Starting $NAME $VERSION..."
+ lock;
+ checkpid;
+
# We actually start them now.
for i in ${SDAEMONS}; do
pstatus ${i};
if [ $? = 0 ]; then
${DIR}/bin/${i};
if [ $? != 0 ]; then
# We actually start them now.
for i in ${SDAEMONS}; do
pstatus ${i};
if [ $? = 0 ]; then
${DIR}/bin/${i};
if [ $? != 0 ]; then
+ echo "${i} did not start";
unlock;
exit 1;
unlock;
exit 1;
- fi
+ fi
- echo "Started ${i}..."
+ echo "Started ${i}..."
else
else
- echo "${i} already running..."
- fi
-
- done
+ echo "${i} already running..."
+ fi
+ done
# After we start we give 2 seconds for the daemons
# to internally create their PID files.
# After we start we give 2 seconds for the daemons
# to internally create their PID files.
@@
-155,16
+147,15
@@
start()
echo "Completed."
}
echo "Completed."
}
-# Process status
pstatus()
{
pfile=$1;
pstatus()
{
pfile=$1;
-
+
# pfile must be set
if [ "X${pfile}" = "X" ]; then
return 0;
fi
# pfile must be set
if [ "X${pfile}" = "X" ]; then
return 0;
fi
-
+
ls ${DIR}/var/run/${pfile}*.pid > /dev/null 2>&1
if [ $? = 0 ]; then
for j in `cat ${DIR}/var/run/${pfile}*.pid 2>/dev/null`; do
ls ${DIR}/var/run/${pfile}*.pid > /dev/null 2>&1
if [ $? = 0 ]; then
for j in `cat ${DIR}/var/run/${pfile}*.pid 2>/dev/null`; do
@@
-174,19
+165,17
@@
pstatus()
rm -f ${DIR}/var/run/${pfile}-$j.pid
continue;
fi
rm -f ${DIR}/var/run/${pfile}-$j.pid
continue;
fi
-
+
kill -0 $j > /dev/null 2>&1
if [ $? = 0 ]; then
return 1;
kill -0 $j > /dev/null 2>&1
if [ $? = 0 ]; then
return 1;
- fi
- done
+ fi
+ done
fi
fi
-
- return 0;
-}
+ return 0;
+}
-# Stop all
stopa()
{
lock;
stopa()
{
lock;
@@
-195,40
+184,47
@@
stopa()
pstatus ${i};
if [ $? = 1 ]; then
echo "Killing ${i} .. ";
pstatus ${i};
if [ $? = 1 ]; then
echo "Killing ${i} .. ";
-
+
kill `cat ${DIR}/var/run/${i}*.pid`;
else
kill `cat ${DIR}/var/run/${i}*.pid`;
else
- echo "${i} not running ..";
+ echo "${i} not running ..";
fi
fi
-
+
rm -f ${DIR}/var/run/${i}*.pid
rm -f ${DIR}/var/run/${i}*.pid
-
- done
-
+ done
+
unlock;
echo "$NAME $VERSION Stopped"
}
unlock;
echo "$NAME $VERSION Stopped"
}
-
### MAIN HERE ###
case "$1" in
### MAIN HERE ###
case "$1" in
- start)
- start
- ;;
- stop)
- stopa
- ;;
- restart)
- stopa
- start
- ;;
- status)
+start)
+ testconfig
+ start
+ ;;
+stop)
+ stopa
+ ;;
+restart)
+ testconfig
+ stopa
+ sleep 1;
+ start
+ ;;
+reload)
+ DAEMONS="ossec-logcollector ossec-syscheckd ossec-agentd"
+ stopa
+ start
+ ;;
+status)
status
status
- ;;
- help)
+ ;;
+help)
help
;;
help
;;
- *)
+*)
help
esac
help
esac
+