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/21 18:06:17 UTC

[35/43] incubator-metron git commit: METRON-70 Create service wrapper for Metron pcap service (nickwallen via cestella) closes apache/incubator-metron#47

METRON-70 Create service wrapper for Metron pcap service (nickwallen via cestella) closes apache/incubator-metron#47


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

Branch: refs/heads/Metron_0.1BETA
Commit: 2b058f2b948cb92136313f953d4cfdfab0a4d69d
Parents: bad4e0e
Author: nickwallen <ni...@nickallen.org>
Authored: Wed Mar 16 16:51:19 2016 -0400
Committer: cstella <ce...@gmail.com>
Committed: Wed Mar 16 16:51:19 2016 -0400

----------------------------------------------------------------------
 .../metron_pcapservice/tasks/config-hbase.yml   | 26 ++++++
 .../metron_pcapservice/tasks/config-java.yml    | 34 ++++++++
 .../metron_pcapservice/tasks/hdfs-site.yml      | 30 -------
 .../roles/metron_pcapservice/tasks/main.yml     | 44 +---------
 .../metron_pcapservice/tasks/pcapservice.yml    | 36 +++++++++
 .../metron_pcapservice/templates/pcapservice    | 84 ++++++++++++++++++++
 .../roles/metron_pcapservice/vars/main.yml      |  4 +-
 7 files changed, 187 insertions(+), 71 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/2b058f2b/deployment/roles/metron_pcapservice/tasks/config-hbase.yml
----------------------------------------------------------------------
diff --git a/deployment/roles/metron_pcapservice/tasks/config-hbase.yml b/deployment/roles/metron_pcapservice/tasks/config-hbase.yml
new file mode 100644
index 0000000..b77c1ec
--- /dev/null
+++ b/deployment/roles/metron_pcapservice/tasks/config-hbase.yml
@@ -0,0 +1,26 @@
+#
+#  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: Fetch hbase-site.xml
+   fetch: src=/etc/hbase/conf/hbase-site.xml dest=/tmp/hbase/conf/hbase-site.xml flat=yes
+   delegate_to: "{{ groups.ambari_slave[0] }}"
+
+ - name: Create hbase conf directory
+   file: path=/etc/hbase/conf state=directory mode=0755
+
+ - name: Copy hbase-site.xml
+   copy: src=/tmp/hbase/conf/hbase-site.xml dest=/etc/hbase/conf/hbase-site.xml mode=0644

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/2b058f2b/deployment/roles/metron_pcapservice/tasks/config-java.yml
----------------------------------------------------------------------
diff --git a/deployment/roles/metron_pcapservice/tasks/config-java.yml b/deployment/roles/metron_pcapservice/tasks/config-java.yml
new file mode 100644
index 0000000..999b9c1
--- /dev/null
+++ b/deployment/roles/metron_pcapservice/tasks/config-java.yml
@@ -0,0 +1,34 @@
+#
+#  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: 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

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/2b058f2b/deployment/roles/metron_pcapservice/tasks/hdfs-site.yml
----------------------------------------------------------------------
diff --git a/deployment/roles/metron_pcapservice/tasks/hdfs-site.yml b/deployment/roles/metron_pcapservice/tasks/hdfs-site.yml
deleted file mode 100644
index 8b435a2..0000000
--- a/deployment/roles/metron_pcapservice/tasks/hdfs-site.yml
+++ /dev/null
@@ -1,30 +0,0 @@
-#
-#  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: Fetch hbase-site.xml
-  fetch: src=/etc/hbase/conf/hbase-site.xml dest=/tmp/hbase/conf/hbase-site.xml flat=yes
-  when: not hbase_site.stat.exists
-  delegate_to: "{{ groups.ambari_slave[0] }}"
-
-- name: Create hbase conf directory
-  file: path=/etc/hbase/conf state=directory mode=0755
-  when: not hbase_site.stat.exists
-
-- name: Copy hbase-site.xml
-  copy: src=/tmp/hbase/conf/hbase-site.xml dest=/etc/hbase/conf/hbase-site.xml mode=0644
-  when: not hbase_site.stat.exists

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/2b058f2b/deployment/roles/metron_pcapservice/tasks/main.yml
----------------------------------------------------------------------
diff --git a/deployment/roles/metron_pcapservice/tasks/main.yml b/deployment/roles/metron_pcapservice/tasks/main.yml
index 989e49b..68da876 100644
--- a/deployment/roles/metron_pcapservice/tasks/main.yml
+++ b/deployment/roles/metron_pcapservice/tasks/main.yml
@@ -15,49 +15,13 @@
 #  limitations under the License.
 #
 ---
-- name: Create Metron streaming directories
-  file: path={{ metron_directory }}/{{ item.name }}  state=directory mode=0755
-  with_items:
-      - { name: 'lib'}
-      - { name: 'config'}
+- include: config-java.yml
 
-- name: Copy Metron pcapservice jar
-  copy:
-    src: "{{ pcapservice_jar_path }}"
-    dest: "{{ metron_directory }}/lib/"
-
-- 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: Check for hase-site
+- name: Check for hbase-site
   stat: path=/etc/hbase/conf/hbase-site.xml
   register: hbase_site
 
-- include: hdfs-site.yml
+- include: config-hbase.yml
   when: not hbase_site.stat.exists
 
-- name: Add hbase-site.xml to pcapservice jar
-  shell: cd /etc/hbase/conf/ && jar -uf {{ metron_directory }}/lib/{{ pcapservice_jar_name }} hbase-site.xml
-
-- name: Install prerequisites
-  yum: name=daemonize
-
-- name: Start pcap_service
-  shell: "daemonize -c {{ metron_directory }} -e /var/log/metron_pcapservice.log -o /var/log/metron_pcapservice.log -l /var/lock/subsys/metron_pcapservice /usr/bin/java -cp {{ metron_directory }}/lib/{{ pcapservice_jar_name }} org.apache.metron.pcapservice.rest.PcapService -p {{ pcapservice_port }}"
-  args:
-    creates: /var/lock/subsys/metron_pcapservice
+- include: pcapservice.yml

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/2b058f2b/deployment/roles/metron_pcapservice/tasks/pcapservice.yml
----------------------------------------------------------------------
diff --git a/deployment/roles/metron_pcapservice/tasks/pcapservice.yml b/deployment/roles/metron_pcapservice/tasks/pcapservice.yml
new file mode 100644
index 0000000..4637311
--- /dev/null
+++ b/deployment/roles/metron_pcapservice/tasks/pcapservice.yml
@@ -0,0 +1,36 @@
+#
+#  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: Create Metron streaming directories
+  file: path={{ metron_directory }}/{{ item.name }}  state=directory mode=0755
+  with_items:
+      - { name: 'lib'}
+      - { name: 'config'}
+
+- name: Copy Metron pcapservice jar
+  copy:
+    src: "{{ pcapservice_jar_src }}"
+    dest: "{{ pcapservice_jar_dst }}"
+
+- name: Add hbase-site.xml to pcapservice jar
+  shell: "jar -uf {{ pcapservice_jar_dst }} /etc/hbase/conf/hbase-site.xml"
+
+- name: Install service script
+  template: src=pcapservice dest=/etc/init.d/pcapservice mode=0755
+
+- name: Start pcapservice
+  service: name=pcapservice state=restarted

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/2b058f2b/deployment/roles/metron_pcapservice/templates/pcapservice
----------------------------------------------------------------------
diff --git a/deployment/roles/metron_pcapservice/templates/pcapservice b/deployment/roles/metron_pcapservice/templates/pcapservice
new file mode 100644
index 0000000..a3ad92b
--- /dev/null
+++ b/deployment/roles/metron_pcapservice/templates/pcapservice
@@ -0,0 +1,84 @@
+#!/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.
+#
+# metron pcap service
+# chkconfig: 345 20 80
+# description: Metron PCAP Service Daemon
+# processname: pcapservice
+#
+NAME=pcapservice
+DESC="Metron pcap service"
+PIDFILE=/var/run/$NAME.pid
+SCRIPTNAME=/etc/init.d/$NAME
+LOGFILE="/var/log/metron_pcapservice.log"
+EXTRA_ARGS="${@:2}"
+DAEMON_PATH="/"
+DAEMON="/usr/bin/java"
+DAEMONOPTS="-cp {{ pcapservice_jar_dst }} org.apache.metron.pcapservice.rest.PcapService -port {{ pcapservice_port }}"
+
+case "$1" in
+  start)
+    printf "%-50s" "Starting $NAME..."
+
+    # kick-off the daemon
+    cd $DAEMON_PATH
+    PID=`$DAEMON $DAEMONOPTS >> $LOGFILE 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

http://git-wip-us.apache.org/repos/asf/incubator-metron/blob/2b058f2b/deployment/roles/metron_pcapservice/vars/main.yml
----------------------------------------------------------------------
diff --git a/deployment/roles/metron_pcapservice/vars/main.yml b/deployment/roles/metron_pcapservice/vars/main.yml
index 4213c86..fdcd6f2 100644
--- a/deployment/roles/metron_pcapservice/vars/main.yml
+++ b/deployment/roles/metron_pcapservice/vars/main.yml
@@ -18,4 +18,6 @@
 metron_version: 0.1BETA
 metron_directory: /usr/metron/{{ metron_version }}
 pcapservice_jar_name: Metron-Pcap_Service-{{ metron_version }}-jar-with-dependencies.jar
-pcapservice_jar_path: "{{ playbook_dir }}/../../metron-streaming/Metron-Pcap_Service/target/{{ pcapservice_jar_name }}"
+pcapservice_jar_src: "{{ playbook_dir }}/../../metron-streaming/Metron-Pcap_Service/target/{{ pcapservice_jar_name }}"
+pcapservice_jar_dst: "{{ metron_directory }}/lib/{{ pcapservice_jar_name }}"
+pcapservice_port: 8081