Hello All,
I copied and pasted the "/etc/init.d/skeleton" file to a new one so I could create my own init script for a program.
Basically the ONLY edit I made to the skeleton "template" so far was to search and replace "FOO" with "snort".
*NOTE: I know there are a bunch of snort init scripts out there, but they weren't working the way I wanted, so I wanted to play around a bit with the init script because I had just recently found out what the 'skeleton' file was for...
But anyway, when I run the script with 'status' as the only argument to the script it seems to execute the init script twice. i.e. It prints out the status twice to the screen...
Like this:
# /etc/init.d/snort_skeleton status
Checking for service snort running
Checking for service snort running
And if I change the line in the script for status from:
/sbin/checkproc $snort_BIN
To This:
OUTPUT=$(/sbin/checkproc $snort_BIN)
echo "OUTPUT='$OUTPUT'"
I get this as the output, which is telling me it's executing twice for some reason...
Checking for service snort OUTPUT = ' '
running
Checking for service snort OUTPUT = ' '
running
Any idea why this would execute twice? Below is the skeleton file, I removed MOST of the comment lines because there are a TON...
Filename: snort_skeleton
Command--> /etc/init.d/snort_skeleton status
#!/bin/sh
# Check for missing binaries (stale symlinks should not happen)
# Note: Special treatment of stop for LSB conformance
snort_BIN=/usr/sbin/snort
test -x $snort_BIN || { echo "$snort_BIN not installed";
if [ "$1" = "stop" ]; then exit 0;
else exit 5; fi; }
# Check for existence of needed config file and read it
snort_CONFIG=/etc/sysconfig/snort
test -r $snort_CONFIG || { echo "$snort_CONFIG not existing";
if [ "$1" = "stop" ]; then exit 0;
else exit 6; fi; }
# Read config
. $snort_CONFIG
. /etc/rc.status
# Reset status of this service
rc_reset
case "$1" in
start)
echo -n "Starting snort "
/sbin/startproc $snort_BIN
# Remember status and be verbose
rc_status -v
;;
stop)
echo -n "Shutting down snort "
/sbin/killproc $snort_BIN
# Remember status and be verbose
rc_status -v
;;
try-restart|condrestart)
if test "$1" = "condrestart"; then
echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
fi
$0 status
if test $? = 0; then
$0 restart
else
rc_reset # Not running is not a failure.
fi
# Remember status and be quiet
rc_status
;;
restart)
$0 stop
$0 start
# Remember status and be quiet
rc_status
;;
force-reload)
echo -n "Reload service snort "
## if it supports it:
/sbin/killproc -HUP $snort_BIN
#touch /var/run/snort.pid
rc_status -v
## Otherwise:
#$0 try-restart
#rc_status
;;
reload)
# If it supports signaling:
echo -n "Reload service snort "
/sbin/killproc -HUP $snort_BIN
#touch /var/run/snort.pid
rc_status -v
## Otherwise if it does not support reload:
#rc_failed 3
#rc_status -v
;;
status)
echo -n "Checking for service snort "
/sbin/checkproc $snort_BIN
rc_status -v
;;
probe)
test /etc/snort/snort.conf -nt /var/run/snort.pid && echo reload
;;
*)
echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
exit 1
;;
esac
rc_exit
If anyone has ANY ideas why this would be happening please feel free...
Any thoughts or suggestions would be greatly appreciated.
Thanks in Advance,
Matt
---------------------------------------------------------------------------------------------------------------------------------------------------
UPDATE:
I added a simple echo statement to the very start of the script on the 1st line after the shebang line:
echo "FIRST LINE:"
Then, I run the script again manually from the command line, with:
./snort_skeleton status
And the Output is:
FIRST LINE:
FIRST LINE:
Checking for service snort running
Checking for service snort running
Just thought that was VERY strange... Any ideas??
Thanks Again,
Matt
---------- Post updated at 04:34 PM ---------- Previous update was at 02:24 PM ----------
Sorry, didn't want to just keep Update/Editing my original post, but I just found something else that seems pretty strange...
If I execute the script and I include a 2nd argument on the cli, NO MATTER WHAT THE ARG IS, it only runs once. I can make the
2nd argument be anything. From another init option like, start|stop|restart|etc... to "foo" to a single number, it ONLY runs once... How
strange is that??
Example:
# ./snort_skeleton status 1
Checking for service snort running
# ./snort_skeleton status foo
Checking for service snort running
# ./snort_skeleton status start
Checking for service snort running
But if I include "status" as the ONLY option I get:
# ./snort_skeleton status
Checking for service snort running
Checking for service snort running
Thought that could possibly help. I do see in the script they use "$@" but that is the only reference I see to more then just the 1st
CLI Option, *i.e. "$2" is not used in the script anywhere...
Any ideas...?
Thanks in Advance,
Matt