Projekt

Obecné

Profil

« Předchozí | Další » 

Revize c988d1b0

Přidáno uživatelem Michal Kliment před více než 3 roky(ů)

ISC KEA support (fixes #1159)

Zobrazit rozdíly:

freenetis-dhcp-sync.sh
################################################################################
# #
# Author: Michal Kliment #
# Description: This script generates config file of ISC DHCP server #
# Description: This script generates config file of DHCP server #
# from FreenetIS #
# #
# Version: 0.1.3 #
......
# Variables
CONFIG=/etc/freenetis/freenetis-dhcp.conf
CUSTOM_DHCP_CONF=/etc/dhcp/dhcp.conf.custom
FORCED=1
# Vesion info? Only possible arg.
......
exit 1
fi
# for old config backward compatibility
if [[ -z "$SERVER" && "$FULL_PATH" == *"etc-dhcp-dhcpd"* ]];
then
SERVER="isc-dhcp"
fi
# DHCP server is old ISC DHCP
if [[ "$SERVER" == "isc-dhcp" ]];
then
DHCP_CONF=${DHCP_CONF:="/etc/dhcp/dhcp.conf"}
CUSTOM_DHCP_CONF=${CUSTOM_DHCP_CONF:="/etc/dhcp/dhcp.conf.custom"}
FULL_PATH=$PATH_FN"/index.php/en/devices/export/"$DEVICE_ID"/debian-etc-dhcp-dhcpd/text"
# DHCP server is newer ISC KEA
elif [[ "$SERVER" == "isc-kea" ]];
then
DHCP_CONF=${DHCP_CONF:="/etc/kea/kea-dhcp4.conf"}
# custom dhcp config is not possible for ISC KEA
CUSTOM_DHCP_CONF=""
FULL_PATH=$PATH_FN"/index.php/en/devices/export/"$DEVICE_ID"/debian-etc-kea-kea-dhcp4/text"
# another DHCP servers are not implemented yet
else
echo "[ERROR] `date -R` Wrong configuration (SERVER not set properly)"
exit 1
fi
# test downloaded config
test_config ()
{
if [[ "$SERVER" == "isc-dhcp" ]];
then
dhcpd -4 -t -cf "$TMPFILE" &>/dev/null
elif [[ "$SERVER" == "isc-kea" ]];
then
kea-dhcp4 -t "$TMPFILE" &>/dev/null
fi
}
# restart DHCP server and test PID
restart_dhcp ()
{
killall -w dhcpd 2>/dev/null
dhcpd -4 -q -cf "$DHCP_CONF"
if [[ "$SERVER" == "isc-dhcp" ]];
then
killall -w dhcpd 2>/dev/null
dhcpd -4 -q -cf "$DHCP_CONF"
pidof -q dhcpd
pidof -q dhcpd
elif [[ "$SERVER" == "isc-kea" ]];
then
if pidof -q kea-dhcp4;
then
killall -s SIGHUP kea-dhcp4 2>/dev/null
else
systemctl start isc-kea-dhcp4-server.service
fi
pidof -q kea-dhcp4
fi
}
# endless loop
......
fi
# download
TMPFILE=`mktemp`
echo "[INFO] `date -R` Downloading ISC DHCP SERVER config from (${PATH_FN})"
echo "[INFO] `date -R` Downloading DHCP SERVER config from (${PATH_FN})"
status=`curl -s -o "$TMPFILE" -w "%{http_code}" "$DOWN_PATH"`
......
echo "[INFO] `date -R` Downloaded (code: $status)"
echo "[INFO] `date -R` Testing new config..."
# new config is valid
if dhcpd -4 -t -cf "$TMPFILE" &>/dev/null;
if test_config;
then
echo "[INFO] `date -R` New config is valid"
echo "[INFO] `date -R` Backuping old config to $DHCP_CONF.save"
......
echo "[INFO] `date -R` Loading new config to $DHCP_CONF.save..."
# copy config
mv -f "$TMPFILE" "$DHCP_CONF"
# make readable for all
chmod +r "$DHCP_CONF"
# restart DHCP server with new configuration
echo "[INFO] `date -R` Restarting ISC DHCP server"
echo "[INFO] `date -R` Restarting DHCP server"
if ! restart_dhcp;
then
echo "[ERROR] `date -R` DHCP server is not running -> keeping old configuration"
mv -f "$DHCP_CONF".save "$DHCP_CONF"
# restart DHCP server with old configuration
echo "[INFO] `date -R` Restarting ISC DHCP server"
echo "[INFO] `date -R` Restarting DHCP server"
if restart_dhcp;
then
echo "[INFO] `date -R` Restart completed"
freenetis-dhcp.conf
# Log file, change to /dev/null to disable logging
LOG_FILE=/var/log/freenetis-dhcp.log
# Filename with ISC DHCP server config
DHCP_CONF="/etc/dhcp/dhcpd.conf"
# DHCP server name (isc-dhcp or isc-kea)
SERVER="isc-dhcp"
# This file (if exists) is attached to generated DHCP conf file
CUSTOM_DHCP_CONF="/etc/dhcp/dhcpd.conf.custom"
# Filename with DHCP server config
# default value for ISC DHCP
# DHCP_CONF="/etc/dhcp/dhcpd.conf"
# default value for ISC KEA
# DHCP_CONF="/etc/kea/kea-dhcp4.conf"
# Full path [DO NOT CHANGE THIS VARIABLE!!!]
FULL_PATH=$PATH_FN"/index.php/en/devices/export/"$DEVICE_ID"/debian-etc-dhcp-dhcpd/text"
# This file (if exists) is attached to generated DHCP conf file
# only for ISC DHCP, default value
# CUSTOM_DHCP_CONF="/etc/dhcp/dhcpd.conf.custom"
freenetis-dhcp.service
[Unit]
Description=FreenetIS DHCP synchronization
After=network.target
Wants=isc-kea-dhcp4-server.service
ConditionPathExists=/etc/freenetis/freenetis-dhcp.conf
[Service]

Také k dispozici: Unified diff