You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@metron.apache.org by ce...@apache.org on 2016/03/09 20:56:31 UTC

incubator-metron git commit: METRON-60 Created service management functionality for Yaf (nickwallen via cestella) closes apache/incubator-metron#37

Repository: incubator-metron
Updated Branches:
  refs/heads/master 3397fb221 -> 8cfd3d529


METRON-60 Created service management functionality for Yaf (nickwallen via cestella) closes apache/incubator-metron#37


Project: http://git-wip-us.apache.org/repos/asf/incubator-metron/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-metron/commit/8cfd3d52
Tree: http://git-wip-us.apache.org/repos/asf/incubator-metron/tree/8cfd3d52
Diff: http://git-wip-us.apache.org/repos/asf/incubator-metron/diff/8cfd3d52

Branch: refs/heads/master
Commit: 8cfd3d5298a3c8d28397f12087f69e314e0770c4
Parents: 3397fb2
Author: nickwallen <ni...@nickallen.org>
Authored: Wed Mar 9 14:56:26 2016 -0500
Committer: cstella <ce...@gmail.com>
Committed: Wed Mar 9 14:56:26 2016 -0500

----------------------------------------------------------------------
 deployment/roles/yaf/defaults/main.yml      |  7 +-
 deployment/roles/yaf/tasks/dependencies.yml | 31 +++++++++
 deployment/roles/yaf/tasks/kafka-client.yml | 27 ++++++++
 deployment/roles/yaf/tasks/main.yml         | 50 +-------------
 deployment/roles/yaf/tasks/yaf.yml          | 15 ++++-
 deployment/roles/yaf/templates/yaf          | 83 ++++++++++++++++++++++++
 6 files changed, 160 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/8cfd3d52/deployment/roles/yaf/defaults/main.yml
----------------------------------------------------------------------
diff --git a/deployment/roles/yaf/defaults/main.yml b/deployment/roles/yaf/defaults/main.yml
index f804cb5..7891ad2 100644
--- a/deployment/roles/yaf/defaults/main.yml
+++ b/deployment/roles/yaf/defaults/main.yml
@@ -21,9 +21,8 @@ yaf_version: 2.8.0
 yaf_home: /opt/yaf
 yaf_topic: ipfix
 hdp_repo_def: http://public-repo-1.hortonworks.com/HDP/centos6/2.x/updates/2.3.2.0/hdp.repo
-yaf: /usr/local/bin/yaf
-yaf_args: ""
-yafscii: /usr/local/bin/yafscii
+yaf_bin: /usr/local/bin/yaf
+yafscii_bin: /usr/local/bin/yafscii
 yaf_log: /var/log/yaf.log
-yaf_lock: /var/lock/subsys/yaf
 kafka_prod: /usr/hdp/current/kafka-broker/bin/kafka-console-producer.sh
+daemon_bin: /usr/local/bin/airdaemon

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/8cfd3d52/deployment/roles/yaf/tasks/dependencies.yml
----------------------------------------------------------------------
diff --git a/deployment/roles/yaf/tasks/dependencies.yml b/deployment/roles/yaf/tasks/dependencies.yml
new file mode 100644
index 0000000..1a28b2a
--- /dev/null
+++ b/deployment/roles/yaf/tasks/dependencies.yml
@@ -0,0 +1,31 @@
+#
+#  Licensed to the Apache Software Foundation (ASF) under one or more
+#  contributor license agreements.  See the NOTICE file distributed with
+#  this work for additional information regarding copyright ownership.
+#  The ASF licenses this file to You under the Apache License, Version 2.0
+#  (the "License"); you may not use this file except in compliance with
+#  the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+#
+---
+- name: Install prerequisites
+  yum: name={{ item }}
+  with_items:
+    - "@Development tools"
+    - libselinux-python
+    - libpcap
+    - libpcap-devel
+    - pcre
+    - pcre-devel
+    - glib2-devel
+    - zlib
+    - zlib-devel
+    - java-1.8.0-openjdk
+    - java-1.8.0-openjdk-devel

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/8cfd3d52/deployment/roles/yaf/tasks/kafka-client.yml
----------------------------------------------------------------------
diff --git a/deployment/roles/yaf/tasks/kafka-client.yml b/deployment/roles/yaf/tasks/kafka-client.yml
new file mode 100644
index 0000000..729929a
--- /dev/null
+++ b/deployment/roles/yaf/tasks/kafka-client.yml
@@ -0,0 +1,27 @@
+#
+#  Licensed to the Apache Software Foundation (ASF) under one or more
+#  contributor license agreements.  See the NOTICE file distributed with
+#  this work for additional information regarding copyright ownership.
+#  The ASF licenses this file to You under the Apache License, Version 2.0
+#  (the "License"); you may not use this file except in compliance with
+#  the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+#
+---
+  - name: Retrieve HDP repository definition
+    get_url:
+      url: "{{ hdp_repo_def }}"
+      dest: /etc/yum.repos.d/hdp.repo
+      mode: 0644
+
+  - name: Install kafka
+    yum: name={{ item }}
+    with_items:
+      - kafka

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/8cfd3d52/deployment/roles/yaf/tasks/main.yml
----------------------------------------------------------------------
diff --git a/deployment/roles/yaf/tasks/main.yml b/deployment/roles/yaf/tasks/main.yml
index 468a4f9..e661f50 100644
--- a/deployment/roles/yaf/tasks/main.yml
+++ b/deployment/roles/yaf/tasks/main.yml
@@ -15,53 +15,7 @@
 #  limitations under the License.
 #
 ---
-- name: Install prerequisites
-  yum: name={{ item }}
-  with_items:
-    - "@Development tools"
-    - libpcap
-    - libpcap-devel
-    - pcre
-    - pcre-devel
-    - glib2-devel
-    - zlib
-    - zlib-devel
-
+- include: dependencies.yml
+- include: kafka-client.yml
 - include: fixbuf.yml
-
 - include: yaf.yml
-
-- name: Turn on promiscuous mode for {{ sniff_interface }}
-  shell: "ip link set {{ sniff_interface }} promisc on"
-
-- name: Retrieve HDP repository definition
-  get_url:
-    url: "{{ hdp_repo_def }}"
-    dest: /etc/yum.repos.d/hdp.repo
-    mode: 0644
-
-- name: Install kafka
-  yum: name=kafka
-
-- name: Check for Java at "{{ java_home }}"
-  stat: path="{{ java_home }}"
-  register: jdk_dir
-
-- name: alternatives link for "java"
-  alternatives: name={{ item.name }} link={{ item.link }}  path={{ item.path }}
-  with_items:
-    - { name: java, link: /usr/bin/java, path: "{{ java_home }}/bin/java" }
-    - { name: jar, link: /usr/bin/jar, path: "{{ java_home }}/bin/jar" }
-  when: jdk_dir.stat.exists
-
-- name: install OpenJdk
-  yum: name={{item}}
-  with_items:
-    - java-1.8.0-openjdk
-    - java-1.8.0-openjdk-devel
-  when: not jdk_dir.stat.exists
-
-- name: Start yaf
-  shell: "daemonize -c {{ yaf_home }} -e {{ yaf_log }} -o {{ yaf_log }} -l {{ yaf_lock }} {{ yaf }} --in {{ sniff_interface }} --live pcap {{ yaf_args }} | {{ yafscii }} --tabular | {{ kafka_prod }} --broker-list {{ kafka_broker_url }} --topic {{ yaf_topic }}"
-  args:
-    creates: "{{ yaf_lock }}"

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/8cfd3d52/deployment/roles/yaf/tasks/yaf.yml
----------------------------------------------------------------------
diff --git a/deployment/roles/yaf/tasks/yaf.yml b/deployment/roles/yaf/tasks/yaf.yml
index db49305..f150127 100644
--- a/deployment/roles/yaf/tasks/yaf.yml
+++ b/deployment/roles/yaf/tasks/yaf.yml
@@ -37,8 +37,21 @@
     - make
     - make install
 
-- name: Create Yaf home directory
+- name: Create yaf home directory
   file:
     path: "{{ yaf_home }}"
     state: directory
     mode: 0755
+
+- name: Install init.d service script
+  template: src=yaf dest=/etc/init.d/yaf mode=0755
+
+- name: Register the service with systemd
+  shell: systemctl enable pcap-replay
+  when: ansible_distribution == "CentOS" and ansible_distribution_major_version == "7"
+
+- name: Turn on promiscuous mode for {{ sniff_interface }}
+  shell: "ip link set {{ sniff_interface }} promisc on"
+
+- name: Start yaf
+  service: name=yaf state=restarted

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/8cfd3d52/deployment/roles/yaf/templates/yaf
----------------------------------------------------------------------
diff --git a/deployment/roles/yaf/templates/yaf b/deployment/roles/yaf/templates/yaf
new file mode 100644
index 0000000..eafd055
--- /dev/null
+++ b/deployment/roles/yaf/templates/yaf
@@ -0,0 +1,83 @@
+#!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# yaf daemon
+# chkconfig: 345 20 80
+# description: Runs yaf - yet another flowmeter
+# processname: yaf
+#
+NAME=yaf
+DESC="Executes yaf - yet another flowmeter"
+PIDFILE=/var/run/$NAME.pid
+SCRIPTNAME=/etc/init.d/$NAME
+EXTRA_ARGS="${@:2}"
+DAEMON_PATH="{{ yaf_home }}"
+DAEMON="{{ daemon_bin }} --airdaemon-pidfile $PIDFILE --log {{ yaf_log }} --retry 15 --retry-max 300 --"
+DAEMONOPTS="{{ yaf_bin }} --in {{ sniff_interface }} --live pcap $EXTRA_ARGS | {{ yafscii_bin }} --tabular | {{ kafka_prod }} --broker-list {{ kafka_broker_url }} --topic {{ yaf_topic }}"
+
+case "$1" in
+  start)
+    printf "%-50s" "Starting $NAME..."
+
+    # kick-off the daemon
+    cd $DAEMON_PATH
+    PID=`$DAEMON $DAEMONOPTS > /dev/null 2>&1 & echo $!`
+    if [ -z $PID ]; then
+        printf "%s\n" "Fail"
+    else
+        echo $PID > $PIDFILE
+        printf "%s\n" "Ok"
+    fi
+  ;;
+
+  status)
+    printf "%-50s" "Checking $NAME..."
+    if [ -f $PIDFILE ]; then
+      PID=`cat $PIDFILE`
+      if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then
+        printf "%s\n" "Process dead but pidfile exists"
+      else
+        echo "Running"
+      fi
+    else
+      printf "%s\n" "Service not running"
+    fi
+  ;;
+
+  stop)
+    printf "%-50s" "Stopping $NAME"
+    PID=`cat $PIDFILE`
+    cd $DAEMON_PATH
+    if [ -f $PIDFILE ]; then
+        kill -HUP $PID
+        printf "%s\n" "Ok"
+        rm -f $PIDFILE
+    else
+        printf "%s\n" "pidfile not found"
+    fi
+  ;;
+
+  restart)
+    $0 stop
+    $0 start
+  ;;
+
+  *)
+    echo "Usage: $0 {status|start|stop|restart}"
+    exit 1
+esac