Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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
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.
# 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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.