2 # ossec-control This shell script takes care of starting
3 # or stopping ossec-hids
4 # Author: Daniel B. Cid <daniel.cid@gmail.com>
12 ### Do not modify bellow here ###
15 AUTHOR="Trend Micro Inc."
16 DAEMONS="ossec-logcollector ossec-syscheckd ossec-agentd ossec-execd"
19 ## Locking for the start/stop
20 LOCK="${DIR}/var/start-script-lock"
21 LOCK_PID="${LOCK}/pid"
24 # This number should be more than enough (even if it is
25 # started multiple times together). It will try for up
26 # to 10 attempts (or 10 seconds) to execute.
34 for i in ${DAEMONS}; do
35 for j in `cat ${DIR}/var/run/${i}*.pid 2>/dev/null`; do
36 ps -p $j |grep ossec >/dev/null 2>&1
38 echo "Deleting PID file '${DIR}/var/run/${i}-${j}.pid' not used..."
39 rm ${DIR}/var/run/${i}-${j}.pid
54 mkdir ${LOCK} > /dev/null 2>&1
56 if [ "${MSL}" = "0" ]; then
57 # Lock aquired (setting the pid)
58 echo "$$" > ${LOCK_PID}
62 # Waiting 1 second before trying again
66 # If PID is not present, speed things a bit.
67 kill -0 `cat ${LOCK_PID}` >/dev/null 2>&1
73 # We tried 10 times to acquire the lock.
74 if [ "$i" = "${MAX_ITERATION}" ]; then
75 # Unlocking and executing
77 mkdir ${LOCK} > /dev/null 2>&1
78 echo "$$" > ${LOCK_PID}
96 echo "Usage: $0 {start|stop|restart|status}";
105 for i in ${DAEMONS}; do
109 echo "${i} not running..."
111 echo "${i} is running..."
119 # We first loop to check the config.
120 for i in ${SDAEMONS}; do
123 echo "${i}: Configuration error. Exiting"
133 SDAEMONS="ossec-execd ossec-agentd ossec-logcollector ossec-syscheckd"
135 echo "Starting $NAME $VERSION (by $AUTHOR)..."
140 # We actually start them now.
141 for i in ${SDAEMONS}; do
146 echo "${i} did not start";
151 echo "Started ${i}..."
153 echo "${i} already running..."
158 # After we start we give 2 seconds for the daemons
159 # to internally create their PID files.
171 if [ "X${pfile}" = "X" ]; then
175 ls ${DIR}/var/run/${pfile}*.pid > /dev/null 2>&1
177 for j in `cat ${DIR}/var/run/${pfile}*.pid 2>/dev/null`; do
178 ps -p $j |grep ossec >/dev/null 2>&1
179 if [ ! $? = 0 ]; then
180 echo "${pfile}: Process $j not used by ossec, removing .."
181 rm -f ${DIR}/var/run/${pfile}-$j.pid
185 kill -0 $j > /dev/null 2>&1
201 for i in ${DAEMONS}; do
204 echo "Killing ${i} .. ";
206 kill `cat ${DIR}/var/run/${i}*.pid`;
208 echo "${i} not running ..";
211 rm -f ${DIR}/var/run/${i}*.pid
216 echo "$NAME $VERSION Stopped"
237 DAEMONS="ossec-logcollector ossec-syscheckd ossec-agentd"