#!/bin/sh
#
# template	Summary of the service.
#
# chkconfig: - 11 91
# description:	The firewall deamon manages the firewall and handles dynamic
#               firewall changes.
# processname: firewalld
# config:	/etc/firewalld
# pidfile:	/var/run/firewalld.pid

### BEGIN INIT INFO
# Provides:  firewalld
# Required-Start: $syslog $local_fs messagebus
# Required-Stop: $local_fs messagebus
# Default-Start: 3 4 5
# Default-Stop: 0 1 6
# Short-Description: The firewall deamon
# Description: The firewall deamon manages the firewall
### END INIT INFO

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

PIDFILE=/var/run/firewalld.pid
LOCKFILE=/var/lock/subsys/firewalld
RETVAL=0

SourceIfNotEmpty /etc/sysconfig/firewalld

start()
{
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root -- firewalld $FIREWALLD_ARGS
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root --name firewalld -- firewalld
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

reload()
{
	msg_reloading firewalld
	firewall-cmd --reload && success || failure
	RETVAL=$?
	echo
	# Seems like firewall-cmd --reload returns 1 even it was successful
	# But who cares?
	#return $RETVAL
	return 0
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	reload)
		reload
		;;
	restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	condreload)
		if [ -e "$LOCKFILE" ]; then
			reload
		fi
		;;
	status)
		status --pidfile "$PIDFILE" --expect-user root --name firewalld -- firewalld
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac

exit $RETVAL
