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 below here ###
15 DAEMONS="ossec-logcollector ossec-syscheckd ossec-agentd ossec-execd"
17 [ -f /etc/ossec-init.conf ] && . /etc/ossec-init.conf
19 ## Locking for the start/stop
20 LOCK="${DIR}/var/start-script-lock"
21 LOCK_PID="${LOCK}/pid"
23 # This number should be more than enough (even if it is
24 # started multiple times together). It will try for up
25 # to 10 attempts (or 10 seconds) to execute.
30 for i in ${DAEMONS}; do
31 for j in `cat ${DIR}/var/run/${i}*.pid 2>/dev/null`; do
32 ps -p $j |grep ossec >/dev/null 2>&1
34 echo "Deleting PID file '${DIR}/var/run/${i}-${j}.pid' not used..."
35 rm ${DIR}/var/run/${i}-${j}.pid
47 mkdir ${LOCK} > /dev/null 2>&1
49 if [ "${MSL}" = "0" ]; then
50 # Lock acquired (setting the pid)
51 echo "$$" > ${LOCK_PID}
55 # Waiting 1 second before trying again
59 # If PID is not present, speed things a bit.
60 kill -0 `cat ${LOCK_PID}` >/dev/null 2>&1
66 # We tried 10 times to acquire the lock.
67 if [ "$i" = "${MAX_ITERATION}" ]; then
68 # Unlocking and executing
70 mkdir ${LOCK} > /dev/null 2>&1
71 echo "$$" > ${LOCK_PID}
85 echo "Usage: $0 {start|stop|reload|restart|status}";
92 for i in ${DAEMONS}; do
96 echo "${i} not running..."
98 echo "${i} is running..."
106 # We first loop to check the config.
107 for i in ${SDAEMONS}; do
110 echo "${i}: Configuration error. Exiting"
120 SDAEMONS="ossec-execd ossec-agentd ossec-logcollector ossec-syscheckd"
122 echo "Starting $NAME $VERSION..."
126 # We actually start them now.
127 for i in ${SDAEMONS}; do
132 echo "${i} did not start";
137 echo "Started ${i}..."
139 echo "${i} already running..."
143 # After we start we give 2 seconds for the daemons
144 # to internally create their PID files.
155 if [ "X${pfile}" = "X" ]; then
159 ls ${DIR}/var/run/${pfile}*.pid > /dev/null 2>&1
161 for j in `cat ${DIR}/var/run/${pfile}*.pid 2>/dev/null`; do
162 ps -p $j |grep ossec >/dev/null 2>&1
163 if [ ! $? = 0 ]; then
164 echo "${pfile}: Process $j not used by ossec, removing .."
165 rm -f ${DIR}/var/run/${pfile}-$j.pid
169 kill -0 $j > /dev/null 2>&1
183 for i in ${DAEMONS}; do
186 echo "Killing ${i} .. ";
188 kill `cat ${DIR}/var/run/${i}*.pid`;
190 echo "${i} not running ..";
193 rm -f ${DIR}/var/run/${i}*.pid
197 echo "$NAME $VERSION Stopped"
217 DAEMONS="ossec-logcollector ossec-syscheckd ossec-agentd"