From e346c99db30654950e119621e87786e0541fe84b Mon Sep 17 00:00:00 2001 From: Marco Platania Date: Fri, 11 Aug 2017 14:33:52 -0400 Subject: [PATCH] Fix vDHCP start Change-Id: I68c8a27b27892fb3a1433f73c7a4e199f3d27a3b Signed-off-by: Marco Platania --- .../kea-sdnc-notify-mod/etc/kea-dhcp4.conf.example | 2 +- vnfs/vCPE/scripts/kea-dhcp4.conf | 2 +- vnfs/vCPE/scripts/v_dhcp.sh | 98 ++++++++++++++++++++++ vnfs/vCPE/scripts/v_dhcp_init.sh | 3 + vnfs/vCPE/scripts/v_dhcp_install.sh | 15 +++- 5 files changed, 115 insertions(+), 5 deletions(-) create mode 100644 vnfs/vCPE/scripts/v_dhcp.sh create mode 100644 vnfs/vCPE/scripts/v_dhcp_init.sh diff --git a/vnfs/vCPE/kea-sdnc-notify-mod/etc/kea-dhcp4.conf.example b/vnfs/vCPE/kea-sdnc-notify-mod/etc/kea-dhcp4.conf.example index b3149af1..fa53f3c5 100644 --- a/vnfs/vCPE/kea-sdnc-notify-mod/etc/kea-dhcp4.conf.example +++ b/vnfs/vCPE/kea-sdnc-notify-mod/etc/kea-dhcp4.conf.example @@ -3,7 +3,7 @@ { # For testing, you can use veth pair as described in README.md "interfaces-config": { - "interfaces": ["veth0" ] + "interfaces": ["eth0" ] }, # How to load the hook library. diff --git a/vnfs/vCPE/scripts/kea-dhcp4.conf b/vnfs/vCPE/scripts/kea-dhcp4.conf index b3149af1..fa53f3c5 100644 --- a/vnfs/vCPE/scripts/kea-dhcp4.conf +++ b/vnfs/vCPE/scripts/kea-dhcp4.conf @@ -3,7 +3,7 @@ { # For testing, you can use veth pair as described in README.md "interfaces-config": { - "interfaces": ["veth0" ] + "interfaces": ["eth0" ] }, # How to load the hook library. diff --git a/vnfs/vCPE/scripts/v_dhcp.sh b/vnfs/vCPE/scripts/v_dhcp.sh new file mode 100644 index 00000000..7799bea2 --- /dev/null +++ b/vnfs/vCPE/scripts/v_dhcp.sh @@ -0,0 +1,98 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Start daemon at boot time +# Description: Enable service provided by daemon. +### END INIT INFO + +dir="/opt" +cmd="./v_dhcp_init.sh" +user="root" + +name=`basename $0` +pid_file="/var/run/$name.pid" +stdout_log="/var/log/$name.log" +stderr_log="/var/log/$name.err" + +get_pid() { + cat "$pid_file" +} + +is_running() { + [ -f "$pid_file" ] && ps `get_pid` > /dev/null 2>&1 +} + +case "$1" in + start) + if is_running; then + echo "Already started" + else + echo "Starting $name" + cd "$dir" + if [ -z "$user" ]; then + sudo $cmd >> "$stdout_log" 2>> "$stderr_log" & + else + sudo -u "$user" $cmd >> "$stdout_log" 2>> "$stderr_log" & + fi + echo $! > "$pid_file" + if ! is_running; then + echo "Unable to start, see $stdout_log and $stderr_log" + exit 1 + fi + fi + ;; + stop) + if is_running; then + echo -n "Stopping $name.." + kill `get_pid` + for i in {1..10} + do + if ! is_running; then + break + fi + + echo -n "." + sleep 1 + done + echo + + if is_running; then + echo "Not stopped; may still be shutting down or shutdown may have failed" + exit 1 + else + echo "Stopped" + if [ -f "$pid_file" ]; then + rm "$pid_file" + fi + fi + else + echo "Not running" + fi + ;; + restart) + $0 stop + if is_running; then + echo "Unable to stop, will not attempt to start" + exit 1 + fi + $0 start + ;; + status) + if is_running; then + echo "Running" + else + echo "Stopped" + exit 1 + fi + ;; + *) + echo "Usage: $0 {start|stop|restart|status}" + exit 1 + ;; +esac + +exit 0 diff --git a/vnfs/vCPE/scripts/v_dhcp_init.sh b/vnfs/vCPE/scripts/v_dhcp_init.sh new file mode 100644 index 00000000..aa32b792 --- /dev/null +++ b/vnfs/vCPE/scripts/v_dhcp_init.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +service kea-dhcp4-server start \ No newline at end of file diff --git a/vnfs/vCPE/scripts/v_dhcp_install.sh b/vnfs/vCPE/scripts/v_dhcp_install.sh index 025b1980..d88ed509 100644 --- a/vnfs/vCPE/scripts/v_dhcp_install.sh +++ b/vnfs/vCPE/scripts/v_dhcp_install.sh @@ -56,20 +56,27 @@ sleep 1 # download the kea hook cd /opt wget $REPO_URL_ARTIFACTS/org/onap/demo/vnf/vcpe/kea-sdnc-notify-mod/$DEMO_ARTIFACTS_VERSION/kea-sdnc-notify-mod-$DEMO_ARTIFACTS_VERSION-demo.tar.gz -tar -zxvf kea-sdnc-notify-mod.tar.gz -mv kea-sdnc-notify-mod VDHCP +tar -zxvf kea-sdnc-notify-mod-$DEMO_ARTIFACTS_VERSION-demo.tar.gz +mv kea-sdnc-notify-mod-$DEMO_ARTIFACTS_VERSION VDHCP rm *.tar.gz cd VDHCP # build.sh takes a minute or two to run ./build.sh -mv kea-sdnc-notify.so /usr/local/lib +mv build/kea-sdnc-notify.so /usr/local/lib # Download DHCP config files cd /opt wget $REPO_URL_BLOB/org.onap.demo/vnfs/vcpe/$INSTALL_SCRIPT_VERSION/kea-dhcp4.conf wget $REPO_URL_BLOB/org.onap.demo/vnfs/vcpe/$INSTALL_SCRIPT_VERSION/kea-sdnc-notify.conf +wget $REPO_URL_BLOB/org.onap.demo/vnfs/vcpe/$INSTALL_SCRIPT_VERSION/v_dhcp_init.sh +wget $REPO_URL_BLOB/org.onap.demo/vnfs/vcpe/$INSTALL_SCRIPT_VERSION/v_dhcp.sh +chmod +x v_dhcp_init.sh +chmod +x v_dhcp.sh +mv v_dhcp.sh /etc/init.d +update-rc.d v_dhcp.sh defaults # Configure DHCP +cp kea-dhcp4.conf /etc/kea-dhcp4-server.conf mv kea-dhcp4.conf /etc/kea/kea-dhcp4.conf mv kea-sdnc-notify.conf /etc/kea/kea-sdnc-notify.conf sleep 1 @@ -96,3 +103,5 @@ then echo "APT::Periodic::Unattended-Upgrade \"0\";" >> /etc/apt/apt.conf.d/10periodic reboot fi + +./v_dhcp_init.sh \ No newline at end of file -- 2.16.6