2 # ossec-control This shell script takes care of starting
3 # or stopping ossec-hids
4 # Author: Daniel B. Cid <daniel.cid@gmail.com>
7 # Getting where we are installed
12 PLIST=${DIR}/bin/.process_list;
15 ### Do not modify bellow here ###
17 # Getting additional processes
18 ls -la ${PLIST} > /dev/null 2>&1
26 AUTHOR="Trend Micro Inc."
27 DAEMONS="ossec-monitord ossec-logcollector ossec-syscheckd ossec-analysisd ossec-maild ossec-execd ${DB_DAEMON} ${CSYSLOG_DAEMON} ${AGENTLESS_DAEMON}"
30 ## Locking for the start/stop
31 LOCK="${DIR}/var/start-script-lock"
32 LOCK_PID="${LOCK}/pid"
35 # This number should be more than enough (even if it is
36 # started multiple times together). It will try for up
37 # to 10 attempts (or 10 seconds) to execute.
45 for i in ${DAEMONS}; do
46 for j in `cat ${DIR}/var/run/${i}*.pid 2>/dev/null`; do
47 ps -p $j |grep ossec >/dev/null 2>&1
49 echo "Deleting PID file '${DIR}/var/run/${i}-${j}.pid' not used..."
50 rm ${DIR}/var/run/${i}-${j}.pid
65 mkdir ${LOCK} > /dev/null 2>&1
67 if [ "${MSL}" = "0" ]; then
68 # Lock aquired (setting the pid)
69 echo "$$" > ${LOCK_PID}
73 # Waiting 1 second before trying again
77 # If PID is not present, speed things a bit.
78 kill -0 `cat ${LOCK_PID}` >/dev/null 2>&1
84 # We tried 10 times to acquire the lock.
85 if [ "$i" = "${MAX_ITERATION}" ]; then
86 # Unlocking and executing
88 mkdir ${LOCK} > /dev/null 2>&1
89 echo "$$" > ${LOCK_PID}
108 echo "Usage: $0 {start|stop|restart|status|enable|disable}";
113 # Enables/disables additional daemons
116 if [ "X$2" = "X" ]; then
118 echo "Enable options: database, client-syslog, agentless, debug"
119 echo "Usage: $0 enable [database|client-syslog|agentless|debug]"
123 if [ "X$2" = "Xdatabase" ]; then
124 echo "DB_DAEMON=ossec-dbd" >> ${PLIST};
125 elif [ "X$2" = "Xclient-syslog" ]; then
126 echo "CSYSLOG_DAEMON=ossec-csyslogd" >> ${PLIST};
127 elif [ "X$2" = "Xagentless" ]; then
128 echo "AGENTLESS_DAEMON=ossec-agentlessd" >> ${PLIST};
129 elif [ "X$2" = "Xdebug" ]; then
130 echo "DEBUG_CLI=\"-d\"" >> ${PLIST};
133 echo "Invalid enable option."
135 echo "Enable options: database, client-syslog, agentless, debug"
136 echo "Usage: $0 enable [database|client-syslog|agentless|debug]"
145 # Enables/disables additional daemons
148 if [ "X$2" = "X" ]; then
150 echo "Disable options: database, client-syslog, agentless, debug"
151 echo "Usage: $0 disable [database|client-syslog|agentless,debug]"
155 if [ "X$2" = "Xdatabase" ]; then
156 echo "DB_DAEMON=\"\"" >> ${PLIST};
157 elif [ "X$2" = "Xclient-syslog" ]; then
158 echo "CSYSLOG_DAEMON=\"\"" >> ${PLIST};
159 elif [ "X$2" = "Xagentless" ]; then
160 echo "AGENTLESS_DAEMON=\"\"" >> ${PLIST};
161 elif [ "X$2" = "Xdebug" ]; then
162 echo "DEBUG_CLI=\"\"" >> ${PLIST};
165 echo "Invalid disable option."
167 echo "Disable options: database, client-syslog, agentless, debug"
168 echo "Usage: $0 disable [database|client-syslog|agentless|debug]"
181 for i in ${DAEMONS}; do
185 echo "${i} not running..."
187 echo "${i} is running..."
195 # We first loop to check the config.
196 for i in ${SDAEMONS}; do
197 ${DIR}/bin/${i} -t ${DEBUG_CLI};
199 echo "${i}: Configuration error. Exiting"
210 SDAEMONS="${DB_DAEMON} ${CSYSLOG_DAEMON} ${AGENTLESS_DAEMON} ossec-maild ossec-execd ossec-analysisd ossec-logcollector ossec-syscheckd ossec-monitord"
212 echo "Starting $NAME $VERSION (by $AUTHOR)..."
213 echo | ${DIR}/bin/ossec-logtest > /dev/null 2>&1;
214 if [ ! $? = 0 ]; then
215 echo "ossec-analysisd: Configuration error. Exiting."
223 # We actually start them now.
224 for i in ${SDAEMONS}; do
227 ${DIR}/bin/${i} ${DEBUG_CLI};
229 echo "${i} did not start correctly.";
234 echo "Started ${i}..."
236 echo "${i} already running..."
241 # After we start we give 2 seconds for the daemons
242 # to internally create their PID files.
246 ls -la "${DIR}/ossec-agent/" >/dev/null 2>&1
249 echo "Starting sub agent directory (for hybrid mode)"
250 ${DIR}/ossec-agent/bin/ossec-control start
262 if [ "X${pfile}" = "X" ]; then
266 ls ${DIR}/var/run/${pfile}*.pid > /dev/null 2>&1
268 for j in `cat ${DIR}/var/run/${pfile}*.pid 2>/dev/null`; do
269 ps -p $j |grep ossec >/dev/null 2>&1
270 if [ ! $? = 0 ]; then
271 echo "${pfile}: Process $j not used by ossec, removing .."
272 rm -f ${DIR}/var/run/${pfile}-$j.pid
276 kill -0 $j > /dev/null 2>&1
292 for i in ${DAEMONS}; do
295 echo "Killing ${i} .. ";
297 kill `cat ${DIR}/var/run/${i}*.pid`;
299 echo "${i} not running ..";
302 rm -f ${DIR}/var/run/${i}*.pid
308 ls -la "${DIR}/ossec-agent/" >/dev/null 2>&1
311 echo "Stopping sub agent directory (for hybrid mode)"
312 ${DIR}/ossec-agent/bin/ossec-control stop
314 echo "$NAME $VERSION Stopped"