Fix vDHCP start 71/7371/1
authorMarco Platania <platania@research.att.com>
Fri, 11 Aug 2017 18:33:52 +0000 (14:33 -0400)
committerMarco Platania <platania@research.att.com>
Fri, 11 Aug 2017 18:33:52 +0000 (14:33 -0400)
Change-Id: I68c8a27b27892fb3a1433f73c7a4e199f3d27a3b
Signed-off-by: Marco Platania <platania@research.att.com>
vnfs/vCPE/kea-sdnc-notify-mod/etc/kea-dhcp4.conf.example
vnfs/vCPE/scripts/kea-dhcp4.conf
vnfs/vCPE/scripts/v_dhcp.sh [new file with mode: 0644]
vnfs/vCPE/scripts/v_dhcp_init.sh [new file with mode: 0644]
vnfs/vCPE/scripts/v_dhcp_install.sh

index b3149af..fa53f3c 100644 (file)
@@ -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.
index b3149af..fa53f3c 100644 (file)
@@ -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 (file)
index 0000000..7799bea
--- /dev/null
@@ -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 (file)
index 0000000..aa32b79
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+service kea-dhcp4-server start
\ No newline at end of file
index 025b198..d88ed50 100644 (file)
@@ -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