LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-01-2006, 10:07 AM   #1
bitpail
LQ Newbie
 
Registered: Oct 2006
Distribution: Fedora 6/SUSE 10
Posts: 20

Rep: Reputation: 0
Problem with Service script.


I have installed fail2ban recently and I want to run it as a service on my FC5 server so that when I reboot, it starts again. There is a init.d file that is provided by the product however it doesn't seem to work. This is what I get:

service fail2ban start
env: /etc/init.d/fail2ban: No such file or directory

even though:

ls -l | grep fail2ban
-rwxr-xr-x 1 root root 1335 Oct 31 16:54 fail2ban

I can start the program fine on the command line by using just

fail2ban

however this doesn't work with the service. Here is the script that was provided by the software package.
---------------------------------------------------------------

#!/bin/bash
#
# fail2ban
#
# chkconfig: 345 91 9
# description: if many unsuccessfull login attempts from some ip address \
# during a short period happen, this address is banned \
# by the firewall
#
# Author: Andrey G. Grozin
#
# $Revision: 1.2 $

# Source function library.
. /etc/init.d/functions

# Get config.
. /etc/sysconfig/network

# Check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0
[ -f /etc/fail2ban.conf ] || exit 0

FAIL2BAN="/usr/bin/fail2ban"
PIDFILE="/var/run/fail2ban.pid"

RETVAL=0

start() {
echo -n $"Starting fail2ban: "
"${FAIL2BAN}" -b > /dev/null
RETVAL=$?
echo
}

stop() {
if [ -f "${PIDFILE}" ]; then
echo -n $"Stopping fail2ban: "
"${FAIL2BAN}" -k > /dev/null
echo
fi
}

restart() {
stop
start
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status fail2ban
RETVAL=$?
;;
reload)
restart
;;
restart)
restart
;;
condrestart)
if [ -f "${PIDFILE}" ]; then
restart
fi
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart}"
exit 1
;;
esac

exit $RETVAL

------------------------------------------------------------

Does anyone have any ideas? I really need this to start on boot.
 
Old 11-01-2006, 11:14 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
Here is a quick intro to init scripts. http://www.netadmintools.com/art94.html

What happends when you add the service via chkconfig -add is that a link is created in the rcx.d directory to start / stop the service during boot. The x corresponds to the runlevel. The link will have a name in this case of s91fail2ban. The s means start and 91 is the order of how the daemons start. 1 being it starts first and 99 last. Since you have not added the daemon yet the service command fails.
 
Old 11-01-2006, 11:59 AM   #3
bitpail
LQ Newbie
 
Registered: Oct 2006
Distribution: Fedora 6/SUSE 10
Posts: 20

Original Poster
Rep: Reputation: 0
Opps, I forgot to add that I did do the following

chkconfig fail2ban --add
chkconfig fail2ban on

Here's a list showing that there are files there:

# for i in 1 2 3 4 5 6
> do
> ls rc$i.d/*fail2ban*
> done
rc1.d/K09fail2ban
rc2.d/S91fail2ban
rc3.d/S91fail2ban
rc4.d/S91fail2ban
rc5.d/S91fail2ban
rc6.d/K09fail2ban

I still experience the same problem. Any ideas?
 
Old 11-01-2006, 01:43 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
Is it listed in the output of chkconfig --lsit?
 
Old 11-01-2006, 01:50 PM   #5
DotHQ
Member
 
Registered: Mar 2006
Location: Ohio, USA
Distribution: Red Hat, Fedora, Knoppix,
Posts: 548

Rep: Reputation: 33
Good luck figuring out why it won't start after reboot. Looks like you've covered all the bases I would think of.

Is there anything in your boot log or messages log showing a problem with starting it?

Like Michaelk said be sure it is listed when you do a chkconfig --list

Let us know if you get it going. Sounds like an addon that I could use.
 
Old 11-01-2006, 03:22 PM   #6
bitpail
LQ Newbie
 
Registered: Oct 2006
Distribution: Fedora 6/SUSE 10
Posts: 20

Original Poster
Rep: Reputation: 0
Here's the output from chkconfig --list

# chkconfig --list | grep fail2ban
fail2ban 0ff 1ff 2n 3n 4n 5n 6ff


By the way those are colons followed by o's, not intended to be face icons

Last edited by bitpail; 11-01-2006 at 03:26 PM.
 
Old 11-01-2006, 05:00 PM   #7
bitpail
LQ Newbie
 
Registered: Oct 2006
Distribution: Fedora 6/SUSE 10
Posts: 20

Original Poster
Rep: Reputation: 0
Got It

Arggghhh!

Wow, this was a dumb mistake. The end-of-line characters were windows for some reason! I used dos2unix on the /etc/init.d/fail2ban. I can't believe it took me that long to figure it out....oh well. Thanks for your help guys! The actual program works fairly well.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
turn a script to a service gsr_kashyap Linux - Software 1 04-05-2006 02:31 AM
Service check script assafde Linux - Networking 1 02-02-2006 06:46 PM
Service check script MPowers Linux - Networking 1 01-24-2006 12:42 AM
Starting a service in a bash script AMMullan Programming 3 02-19-2004 11:06 AM
script to check if the service is running eyt Linux - Newbie 2 02-16-2004 07:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration