hostapd init script for Redhat/CentOS

Hostapd is a software daemon that turns a Linux box into a full blown wireless access point, but it doesn’t come with an init script to automatically start it when the machine boots up. It seems each Linux distribution that supports hostapd does their own thing, so I went ahead and created this little init script to cleanly start/stop hostapd on a CentOS/Redhat box.

#!/bin/sh
#
# start/stop the hostapd server
#
# chkconfig: 2345 99 10
# description: hostap daemon
# processname: hostapd
# config: /etc/hostapd.conf
# pidfile: /var/run/hostapd.pid
#
PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin
export PATH

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

stop()
{
 echo -n "Stopping hostapd daemon: "
        killproc hostapd
        echo
        rm -f /var/lock/subsys/hostapd

}

start()
{
        echo -n "Starting hostapd daemon: "
        daemon /usr/local/bin/hostapd /etc/hostapd.conf -P /var/run/hostapd.pid -B
        echo
        touch /var/lock/subsys/hostapd
}

# See how we were called.
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    status)
        status hostapd
        ;;
    restart)
        stop
        start
        ;;
    *)
        echo "Usage: hostapd {start|stop|status|restart}"
        exit 1
esac

exit 0

You can check out hostapd here:
http://hostap.epitest.fi/hostapd/

I really do think this is the same software many consumer-grade routers are running.

No Comments.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Anti-Spam Quiz: