metron-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l...@apache.org
Subject metron git commit: METRON-938 "service metron-rest start <password>" does not work on CentOS 7. (justinleet) closes apache/metron#757
Date Fri, 22 Sep 2017 13:43:40 GMT
Repository: metron
Updated Branches:
  refs/heads/master 529ea6cc4 -> 5f13e14be


METRON-938 "service metron-rest start <password>" does not work on CentOS 7. (justinleet)
closes apache/metron#757


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

Branch: refs/heads/master
Commit: 5f13e14be57e3a4375ae6fe63c8debf3803d6e44
Parents: 529ea6c
Author: justinleet <justinjleet@gmail.com>
Authored: Fri Sep 22 09:41:35 2017 -0400
Committer: leet <leet@apache.org>
Committed: Fri Sep 22 09:41:35 2017 -0400

----------------------------------------------------------------------
 .../CURRENT/configuration/metron-rest-env.xml   |  35 ++++
 .../package/scripts/params/params_linux.py      |  13 +-
 .../CURRENT/package/scripts/rest_commands.py    |  93 +++++++++-
 .../METRON/CURRENT/service_advisor.py           |   4 +
 .../docker/rpm-docker/SPECS/metron.spec         |  12 +-
 .../packaging/docker/rpm-docker/build.sh        |  11 +-
 metron-interface/metron-rest/README.md          |  37 ++--
 .../metron-rest/src/main/scripts/metron-rest    | 185 -------------------
 .../metron-rest/src/main/scripts/metron-rest.sh |  87 +++++++++
 9 files changed, 261 insertions(+), 216 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/metron/blob/5f13e14b/metron-deployment/packaging/ambari/metron-mpack/src/main/resources/common-services/METRON/CURRENT/configuration/metron-rest-env.xml
----------------------------------------------------------------------
diff --git a/metron-deployment/packaging/ambari/metron-mpack/src/main/resources/common-services/METRON/CURRENT/configuration/metron-rest-env.xml
b/metron-deployment/packaging/ambari/metron-mpack/src/main/resources/common-services/METRON/CURRENT/configuration/metron-rest-env.xml
index 0549510..8ba29b5 100644
--- a/metron-deployment/packaging/ambari/metron-mpack/src/main/resources/common-services/METRON/CURRENT/configuration/metron-rest-env.xml
+++ b/metron-deployment/packaging/ambari/metron-mpack/src/main/resources/common-services/METRON/CURRENT/configuration/metron-rest-env.xml
@@ -109,4 +109,39 @@
         <value>escalation</value>
         <display-name>Metron escalation topic</display-name>
     </property>
+    <property>
+        <name>metron_rest_classpath</name>
+        <description>Additional classpath for metron REST.</description>
+        <value/>
+        <display-name>Metron rest additional classpath</display-name>
+        <value-attributes>
+            <empty-value-valid>true</empty-value-valid>
+        </value-attributes>
+    </property>
+    <property>
+        <name>metron_indexing_classpath</name>
+        <description>Classpath for metron indexing if Elasticsearch isn't being used</description>
+        <value/>
+        <display-name>Metron indexing classpath</display-name>
+        <value-attributes>
+            <empty-value-valid>true</empty-value-valid>
+        </value-attributes>
+    </property>
+    <property>
+        <name>metron_sysconfig</name>
+        <description>Local location of a custom sysconfig</description>
+        <value>/etc/default/metron</value>
+        <display-name>Metron sysconfig</display-name>
+    </property>
+    <property>
+        <name>metron_rest_pid_dir</name>
+        <value>/var/run/metron</value>
+        <display-name>Metron REST PID Dir</display-name>
+        <description>Metron REST PID Dir.</description>
+        <value-attributes>
+            <type>directory</type>
+            <overridable>false</overridable>
+            <editable-only-at-install>true</editable-only-at-install>
+        </value-attributes>
+    </property>
 </configuration>

http://git-wip-us.apache.org/repos/asf/metron/blob/5f13e14b/metron-deployment/packaging/ambari/metron-mpack/src/main/resources/common-services/METRON/CURRENT/package/scripts/params/params_linux.py
----------------------------------------------------------------------
diff --git a/metron-deployment/packaging/ambari/metron-mpack/src/main/resources/common-services/METRON/CURRENT/package/scripts/params/params_linux.py
b/metron-deployment/packaging/ambari/metron-mpack/src/main/resources/common-services/METRON/CURRENT/package/scripts/params/params_linux.py
index 3bfe8e3..b73c3ef 100755
--- a/metron-deployment/packaging/ambari/metron-mpack/src/main/resources/common-services/METRON/CURRENT/package/scripts/params/params_linux.py
+++ b/metron-deployment/packaging/ambari/metron-mpack/src/main/resources/common-services/METRON/CURRENT/package/scripts/params/params_linux.py
@@ -29,6 +29,9 @@ from resource_management.libraries.functions.default import default
 from resource_management.libraries.functions.get_not_managed_resources import get_not_managed_resources
 from resource_management.libraries.resources.hdfs_resource import HdfsResource
 from resource_management.libraries.script import Script
+from resource_management.libraries.functions.version import format_stack_version
+from resource_management.libraries.functions.stack_features import check_stack_feature
+from resource_management.libraries.functions import StackFeature
 
 import status_params
 
@@ -38,6 +41,7 @@ tmp_dir = Script.get_tmp_dir()
 
 hostname = config['hostname']
 metron_home = status_params.metron_home
+
 parsers = status_params.parsers
 parser_error_topic = config['configurations']['metron-parsers-env']['parser_error_topic']
 geoip_hdfs_dir = "/apps/metron/geo/default/"
@@ -169,7 +173,7 @@ HdfsResource = functools.partial(
     dfs_type=dfs_type
 )
 
-# HBase
+# Metron HBase configuration
 enrichment_hbase_provider_impl = 'org.apache.metron.hbase.HTableProvider'
 enrichment_hbase_table = status_params.enrichment_hbase_table
 enrichment_hbase_cf = status_params.enrichment_hbase_cf
@@ -233,6 +237,13 @@ if security_enabled:
 # Management UI
 metron_rest_host = default("/clusterHostInfo/metron_rest_hosts", ['localhost'])[0]
 
+# REST
+metron_rest_pid_dir = config['configurations']['metron-rest-env']['metron_rest_pid_dir']
+metron_rest_pid = 'metron-rest.pid'
+metron_indexing_classpath = config['configurations']['metron-rest-env']['metron_indexing_classpath']
+metron_rest_classpath = config['configurations']['metron-rest-env']['metron_rest_classpath']
+metron_sysconfig = config['configurations']['metron-rest-env']['metron_sysconfig']
+
 # Enrichment
 geoip_url = config['configurations']['metron-enrichment-env']['geoip_url']
 enrichment_host_known_hosts = config['configurations']['metron-enrichment-env']['enrichment_host_known_hosts']

http://git-wip-us.apache.org/repos/asf/metron/blob/5f13e14b/metron-deployment/packaging/ambari/metron-mpack/src/main/resources/common-services/METRON/CURRENT/package/scripts/rest_commands.py
----------------------------------------------------------------------
diff --git a/metron-deployment/packaging/ambari/metron-mpack/src/main/resources/common-services/METRON/CURRENT/package/scripts/rest_commands.py
b/metron-deployment/packaging/ambari/metron-mpack/src/main/resources/common-services/METRON/CURRENT/package/scripts/rest_commands.py
index 9424075..09d7106 100755
--- a/metron-deployment/packaging/ambari/metron-mpack/src/main/resources/common-services/METRON/CURRENT/package/scripts/rest_commands.py
+++ b/metron-deployment/packaging/ambari/metron-mpack/src/main/resources/common-services/METRON/CURRENT/package/scripts/rest_commands.py
@@ -21,10 +21,14 @@ import os
 
 from datetime import datetime
 from resource_management.core.logger import Logger
-from resource_management.core.resources.system import Execute, File
+from resource_management.core.resources.system import Directory, Execute, File
+from resource_management.libraries.functions import get_user_call_output
 from resource_management.libraries.functions.format import format
+from resource_management.libraries.functions.show_logs import show_logs
 
 import metron_service
+from metron_security import kinit
+
 
 # Wrap major operations and functionality in this class
 class RestCommands:
@@ -36,6 +40,18 @@ class RestCommands:
             raise ValueError("params argument is required for initialization")
         self.__params = params
         self.__acl_configured = os.path.isfile(self.__params.rest_acl_configured_flag_file)
+        Directory(params.metron_rest_pid_dir,
+                  mode=0755,
+                  owner=params.metron_user,
+                  group=params.metron_group,
+                  create_parents=True
+                  )
+        Directory(params.metron_log_dir,
+                  mode=0755,
+                  owner=params.metron_user,
+                  group=params.metron_group,
+                  create_parents=True
+                  )
 
     def is_acl_configured(self):
         return self.__acl_configured
@@ -56,17 +72,82 @@ class RestCommands:
 
     def start_rest_application(self):
         Logger.info('Starting REST application')
-        command = format("service metron-rest start {metron_jdbc_password!p}")
-        Execute(command)
+
+        if self.__params.security_enabled:
+            kinit(self.__params.kinit_path_local,
+            self.__params.metron_keytab_path,
+            self.__params.metron_principal_name,
+            execute_user=self.__params.metron_user)
+
+        # Get the PID associated with the service
+        pid_file = format("{metron_rest_pid_dir}/{metron_rest_pid}")
+        pid = get_user_call_output.get_user_call_output(format("cat {pid_file}"), user=self.__params.metron_user,
is_checked_call=False)[1]
+        process_id_exists_command = format("ls {pid_file} >/dev/null 2>&1 &&
ps -p {pid} >/dev/null 2>&1")
+
+        # Set the password with env variable instead of param to avoid it showing in ps
+        cmd = format((
+          "export METRON_JDBC_PASSWORD={metron_jdbc_password!p};"
+          "export JAVA_HOME={java_home};"
+          "export METRON_REST_CLASSPATH={metron_rest_classpath};"
+          "export METRON_INDEX_CP={metron_indexing_classpath};"
+          "export METRON_LOG_DIR={metron_log_dir};"
+          "export METRON_PID_FILE={pid_file};"
+          "{metron_home}/bin/metron-rest.sh;"
+          "unset METRON_JDBC_PASSWORD;"
+        ))
+
+        Execute(cmd,
+                user = self.__params.metron_user,
+                logoutput=True,
+                not_if = process_id_exists_command,
+                timeout=60)
         Logger.info('Done starting REST application')
 
     def stop_rest_application(self):
         Logger.info('Stopping REST application')
-        Execute("service metron-rest stop")
+
+        # Get the pid associated with the service
+        pid_file = format("{metron_rest_pid_dir}/{metron_rest_pid}")
+        pid = get_user_call_output.get_user_call_output(format("cat {pid_file}"), user=self.__params.metron_user,
is_checked_call=False)[1]
+        process_id_exists_command = format("ls {pid_file} >/dev/null 2>&1 &&
ps -p {pid} >/dev/null 2>&1")
+
+        if self.__params.security_enabled:
+            kinit(self.__params.kinit_path_local,
+            self.__params.metron_keytab_path,
+            self.__params.metron_principal_name,
+            execute_user=self.__params.metron_user)
+
+        # Politely kill
+        kill_cmd = ('kill', format("{pid}"))
+        Execute(kill_cmd,
+                sudo=True,
+                not_if = format("! ({process_id_exists_command})")
+                )
+
+        # Violently kill
+        hard_kill_cmd = ('kill', '-9', format("{pid}"))
+        wait_time = 5
+        Execute(hard_kill_cmd,
+                not_if = format("! ({process_id_exists_command}) || ( sleep {wait_time} &&
! ({process_id_exists_command}) )"),
+                sudo=True,
+                ignore_failures = True
+                )
+
+        try:
+            # check if stopped the process, else fail the task
+            Execute(format("! ({process_id_exists_command})"),
+                tries=20,
+                try_sleep=3,
+                  )
+        except:
+            show_logs(self.__params.metron_log_dir, self.__params.metron_user)
+            raise
+
+        File(pid_file, action = "delete")
         Logger.info('Done stopping REST application')
 
     def restart_rest_application(self, env):
         Logger.info('Restarting the REST application')
-        command = format("service metron-rest restart {metron_jdbc_password!p}")
-        Execute(command)
+        self.stop_rest_application()
+        self.start_rest_application()
         Logger.info('Done restarting the REST application')

http://git-wip-us.apache.org/repos/asf/metron/blob/5f13e14b/metron-deployment/packaging/ambari/metron-mpack/src/main/resources/common-services/METRON/CURRENT/service_advisor.py
----------------------------------------------------------------------
diff --git a/metron-deployment/packaging/ambari/metron-mpack/src/main/resources/common-services/METRON/CURRENT/service_advisor.py
b/metron-deployment/packaging/ambari/metron-mpack/src/main/resources/common-services/METRON/CURRENT/service_advisor.py
index 1a9d195..56fdab8 100644
--- a/metron-deployment/packaging/ambari/metron-mpack/src/main/resources/common-services/METRON/CURRENT/service_advisor.py
+++ b/metron-deployment/packaging/ambari/metron-mpack/src/main/resources/common-services/METRON/CURRENT/service_advisor.py
@@ -69,6 +69,10 @@ class METRON${metron.short.version}ServiceAdvisor(service_advisor.ServiceAdvisor
             message = "Metron REST must be colocated with an instance of STORM SUPERVISOR"
             items.append({ "type": 'host-component', "level": 'WARN', "message": message,
"component-name": 'METRON_REST', "host": metronRESTHost })
 
+        if metronParsersHost !=  metronRESTHost:
+            message = "Metron REST must be co-located with Metron Parsers on {0}".format(metronParsersHost)
+            items.append({ "type": 'host-component', "level": 'WARN', "message": message,
"component-name": 'METRON_REST', "host": metronRESTHost })
+
         if metronParsersHost != metronEnrichmentMaster:
             message = "Metron Enrichment Master must be co-located with Metron Parsers on
{0}".format(metronParsersHost)
             items.append({ "type": 'host-component', "level": 'ERROR', "message": message,
"component-name": 'METRON_ENRICHMENT_MASTER', "host": metronEnrichmentMaster })

http://git-wip-us.apache.org/repos/asf/metron/blob/5f13e14b/metron-deployment/packaging/docker/rpm-docker/SPECS/metron.spec
----------------------------------------------------------------------
diff --git a/metron-deployment/packaging/docker/rpm-docker/SPECS/metron.spec b/metron-deployment/packaging/docker/rpm-docker/SPECS/metron.spec
index 26f626b..43f2c67 100644
--- a/metron-deployment/packaging/docker/rpm-docker/SPECS/metron.spec
+++ b/metron-deployment/packaging/docker/rpm-docker/SPECS/metron.spec
@@ -92,7 +92,6 @@ tar -xzf %{SOURCE10} -C %{buildroot}%{metron_home}
 tar -xzf %{SOURCE11} -C %{buildroot}%{metron_home}
 tar -xzf %{SOURCE12} -C %{buildroot}%{metron_home}
 
-install %{buildroot}%{metron_home}/bin/metron-rest %{buildroot}/etc/init.d/
 install %{buildroot}%{metron_home}/bin/metron-management-ui %{buildroot}/etc/init.d/
 
 # allows node dependencies to be packaged in the RPMs
@@ -372,16 +371,9 @@ This package installs the Metron Rest %{metron_home}
 %dir %{metron_home}/bin
 %dir %{metron_home}/lib
 %{metron_home}/config/rest_application.yml
-%{metron_home}/bin/metron-rest
-/etc/init.d/metron-rest
+%{metron_home}/bin/metron-rest.sh
 %attr(0644,root,root) %{metron_home}/lib/metron-rest-%{full_version}.jar
 
-%post rest
-chkconfig --add metron-rest
-
-%preun rest
-chkconfig --del metron-rest
-
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 %package        config
@@ -460,6 +452,8 @@ This package install the Metron MaaS Service files %{metron_home}
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 %changelog
+* Tue Sep 19 2017 Apache Metron <dev@metron.apache.org> - 0.4.2
+- Updated and renamed metron-rest script
 * Tue Aug 29 2017 Apache Metron <dev@metron.apache.org> - 0.4.1
 - Add Metron MaaS service
 * Thu Jun 29 2017 Apache Metron <dev@metron.apache.org> - 0.4.1

http://git-wip-us.apache.org/repos/asf/metron/blob/5f13e14b/metron-deployment/packaging/docker/rpm-docker/build.sh
----------------------------------------------------------------------
diff --git a/metron-deployment/packaging/docker/rpm-docker/build.sh b/metron-deployment/packaging/docker/rpm-docker/build.sh
index dd5149d..68566b7 100755
--- a/metron-deployment/packaging/docker/rpm-docker/build.sh
+++ b/metron-deployment/packaging/docker/rpm-docker/build.sh
@@ -20,6 +20,7 @@
 # Spec's release, not in the version.  Make sure this is split out based on the acutal version.
 # E.g. 0.2.0BETA becomes 0.2.0 version and BETA prerelease.
 # Empty string is acceptable when there is no prerelease tag.
+
 FULL_VERSION=$1
 echo "FULL_VERSION: ${FULL_VERSION}"
 VERSION=$(echo ${FULL_VERSION} | tr -d '"'"'[:alpha:]'"'"')
@@ -35,8 +36,14 @@ if [ $? -ne 0 ] && [ $OWNER_UID -ne 0 ]; then
     useradd -u $OWNER_UID builder
 fi
 
-rm -rf SRPMS/ RPMS/ && \
-QA_SKIP_BUILD_ROOT=1 rpmbuild -v -ba --define "_topdir $(pwd)" --define "_version ${VERSION}"
--define "_prerelease ${PRERELEASE}" SPECS/metron.spec && \
+rm -rf SRPMS/ RPMS/
+
+QA_SKIP_BUILD_ROOT=1 rpmbuild -v -ba --define "_topdir $(pwd)" --define "_version ${VERSION}"
--define "_prerelease ${PRERELEASE}" SPECS/metron.spec
+if [ $? -ne 0 ]; then
+  echo "RPM build errors encountered" >&2
+  exit 1
+fi
+
 rpmlint -i SPECS/metron.spec RPMS/*/metron* SRPMS/metron
 
 # Ensure original user permissions are maintained after build

http://git-wip-us.apache.org/repos/asf/metron/blob/5f13e14b/metron-interface/metron-rest/README.md
----------------------------------------------------------------------
diff --git a/metron-interface/metron-rest/README.md b/metron-interface/metron-rest/README.md
index 97ab95c..3d8d83b 100644
--- a/metron-interface/metron-rest/README.md
+++ b/metron-interface/metron-rest/README.md
@@ -59,9 +59,8 @@ No optional parameter has a default.
 ### Optional - With Defaults
 | Environment Variable                  | Description                                   
                   | Required | Default
 | ------------------------------------- | -----------------------------------------------------------------
| -------- | -------
-| METRON_USER                           | Run the application as this user              
                   | Optional | metron
 | METRON_LOG_DIR                        | Directory where the log file is written       
                   | Optional | /var/log/metron/
-| METRON_PID_DIR                        | Directory where the pid file is written       
                   | Optional | /var/run/metron/
+| METRON_PID_FILE                       | File where the pid is written                 
                   | Optional | /var/run/metron/
 | METRON_REST_PORT                      | REST application port                         
                   | Optional | 8082
 | METRON_JDBC_CLIENT_PATH               | Path to JDBC client jar                       
                   | Optional | H2 is bundled
 | METRON_TEMP_GROK_PATH                 | Temporary directory used to test grok statements
                 | Optional | ./patterns/temp
@@ -92,7 +91,6 @@ For example, edit these variables in `/etc/sysconfig/metron` before starting
the
 METRON_JDBC_DRIVER="org.h2.Driver"
 METRON_JDBC_URL="jdbc:h2:file:~/metrondb"
 METRON_JDBC_USERNAME="root"
-METRON_JDBC_PASSWORD='root"
 METRON_JDBC_PLATFORM="h2"
 ```
 
@@ -100,7 +98,15 @@ METRON_JDBC_PLATFORM="h2"
 
 The REST application should be configured with a production-grade database outside of development.
 
-For example, the following configures the application for MySQL:
+#### Ambari Install
+
+Installing with Ambari is recommended for production deployments.
+Ambari handles setup, configuration, and management of the REST component.
+This includes managing the PID file, directing logging, etc.
+
+#### Manual Install
+
+The following configures the application for MySQL:
 
 1. Install MySQL if not already available (this example uses version 5.7, installation instructions
can be found [here](https://dev.mysql.com/doc/refman/5.7/en/linux-installation-yum-repo.html))
 
@@ -127,17 +133,22 @@ METRON_JDBC_PLATFORM="mysql"
 METRON_JDBC_CLIENT_PATH=$METRON_HOME/lib/mysql-connector-java-5.1.41/mysql-connector-java-5.1.41-bin.jar
   ```
 
-## Usage
+1. Switch to the metron user
+  ```
+sudo su - metron
+  ```
 
-After configuration is complete, the REST application can be managed as a service:
-```
-service metron-rest start
-```
+1. Start the REST API. Adjust the password as necessary.
+  ```
+set -o allexport;
+source /etc/metron/sysconfig;
+set +o allexport;
+export METRON_JDBC_PASSWORD='Myp@ssw0rd';
+$METRON_HOME/bin/metron-rest.sh
+unset METRON_JDBC_PASSWORD;
+  ```
 
-If a production database is configured, the JDBC password should be passed in as the first
argument on startup:
-```
-service metron-rest start Myp@ssw0rd
-```
+## Usage
 
 The REST application can be accessed with the Swagger UI at http://host:port/swagger-ui.html#/.
 The default port is 8082.
 

http://git-wip-us.apache.org/repos/asf/metron/blob/5f13e14b/metron-interface/metron-rest/src/main/scripts/metron-rest
----------------------------------------------------------------------
diff --git a/metron-interface/metron-rest/src/main/scripts/metron-rest b/metron-interface/metron-rest/src/main/scripts/metron-rest
deleted file mode 100644
index 0d99617..0000000
--- a/metron-interface/metron-rest/src/main/scripts/metron-rest
+++ /dev/null
@@ -1,185 +0,0 @@
-#!/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 rest application service
-# chkconfig: - 20 80
-# description: rest application
-# processname: metron-rest
-#
-
-# all LSB compliant distributions provide the following
-# http://refspecs.linuxbase.org/LSB_3.0.0/LSB-PDA/LSB-PDA/iniscrptfunc.html
-if [ -f /lib/lsb/init-functions ]; then
-    . /lib/lsb/init-functions
-fi
-
-NAME=metron-rest
-DESC="Metron REST Application"
-METRON_VERSION=${project.version}
-METRON_HOME=/usr/metron/$METRON_VERSION
-METRON_LOG_DIR="/var/log/metron"
-METRON_PID_DIR="/var/run/metron"
-METRON_USER="metron"
-METRON_GROUP="metron"
-METRON_REST_PORT=8082
-METRON_JDBC_PASSWORD="$2"
-METRON_SYSCONFIG="/etc/default/metron"
-if [ -f "$METRON_SYSCONFIG" ]; then
-    set -a
-    . "$METRON_SYSCONFIG"
-fi
-
-HBASE_HOME=${HBASE_HOME:-/usr/hdp/current/hbase-client}
-PIDFILE="$METRON_PID_DIR/$NAME.pid"
-LOCKFILE=/var/lock/subsys/$NAME
-
-METRON_REST_CLASSPATH="$HADOOP_CONF_DIR:${HBASE_HOME}/conf:$METRON_HOME/lib/metron-rest-$METRON_VERSION.jar"
-
-# the vagrant Spring profile provides configuration values, otherwise configuration is provided
by rest_application.yml
-if [[ !($METRON_SPRING_PROFILES_ACTIVE == *"vagrant"*) ]]; then
-  METRON_SPRING_OPTIONS+=" --spring.config.location=$METRON_HOME/config/rest_application.yml"
-fi
-METRON_SPRING_OPTIONS+=" --server.port=$METRON_REST_PORT"
-if [ $METRON_SPRING_PROFILES_ACTIVE ]; then
-    METRON_SPRING_OPTIONS+=" --spring.profiles.active=$METRON_SPRING_PROFILES_ACTIVE"
-fi
-if [ $METRON_JDBC_PASSWORD ]; then
-    METRON_SPRING_OPTIONS+=" --spring.datasource.password=$METRON_JDBC_PASSWORD"
-fi
-if [ $METRON_JDBC_CLIENT_PATH ]; then
-    METRON_REST_CLASSPATH+=":$METRON_JDBC_CLIENT_PATH"
-fi
-if [ $METRON_INDEX_CP ]; then
-    METRON_REST_CLASSPATH+=":$METRON_INDEX_CP"
-else
-    METRON_REST_CLASSPATH+=":$METRON_HOME/lib/metron-elasticsearch-$METRON_VERSION-uber.jar"
-fi
-METRON_JVMFLAGS+=" -cp $METRON_REST_CLASSPATH"
-DAEMON="$JAVA_HOME/bin/java $METRON_JVMFLAGS org.apache.metron.rest.MetronRestApplication
$METRON_SPRING_OPTIONS"
-
-#
-# start the rest application
-#
-start() {
-
-  # if pidfile exists, do not start another
-  if [ -f $PIDFILE ]; then
-      PID=`cat $PIDFILE`
-      printf "OK [$PID]\n"
-      return
-  fi
-
-  if [ ! -d "$METRON_LOG_DIR" ]; then
-      mkdir -p "$METRON_LOG_DIR" && chown "$METRON_USER":"$METRON_GROUP" "$METRON_LOG_DIR"
-  fi
-
-  if [ ! -d "$METRON_PID_DIR" ]; then
-      mkdir -p "$METRON_PID_DIR" && chown "$METRON_USER":"$METRON_GROUP" "$METRON_PID_DIR"
-  fi
-
-  # kick-off the daemon
-  CMD="$DAEMON >> $METRON_LOG_DIR/$NAME.log 2>&1 & echo \$!"
-  PID=`su -c "$CMD" $METRON_USER`
-
-  if [ -z $PID ]; then
-      printf "Fail\n"
-  else
-      echo $PID > $PIDFILE
-      printf "Ok [$PID]\n"
-  fi
-}
-
-#
-# stop the rest application
-#
-stop() {
-  if [ -f $PIDFILE ]; then
-    PID=`cat $PIDFILE`
-    while sleep 1
-      echo -n "."
-      kill -0 $PID >/dev/null 2>&1
-    do
-      kill $PID
-    done
-    rm -f $PIDFILE
-    printf "%s\n" "Ok"
-  else
-      printf "%s\n" "Not running"
-  fi
-}
-
-#
-# status check of the rest application
-#
-status() {
-  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
-}
-
-case "$1" in
-
-  ##############################################################################
-  # start
-  #
-  start)
-    printf "%-50s \n" "Starting $NAME..."
-    start
-  ;;
-
-  ##############################################################################
-  # status
-  #
-  status)
-    printf "%-50s \n" "Checking $NAME..."
-    status
-  ;;
-
-  ##############################################################################
-  # stop
-  #
-  stop)
-    printf "%-50s \n" "Stopping $NAME..."
-    stop
-  ;;
-
-  ##############################################################################
-  # restart
-  #
-  restart)
-    $0 stop
-    $0 start $2
-  ;;
-
-  ##############################################################################
-  # reload
-  #
-  reload)
-  ;;
-
-  *)
-    echo "Usage: $0 {status|start|stop|restart}"
-    exit 1
-esac

http://git-wip-us.apache.org/repos/asf/metron/blob/5f13e14b/metron-interface/metron-rest/src/main/scripts/metron-rest.sh
----------------------------------------------------------------------
diff --git a/metron-interface/metron-rest/src/main/scripts/metron-rest.sh b/metron-interface/metron-rest/src/main/scripts/metron-rest.sh
new file mode 100644
index 0000000..638589a
--- /dev/null
+++ b/metron-interface/metron-rest/src/main/scripts/metron-rest.sh
@@ -0,0 +1,87 @@
+#!/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.
+#
+
+if [ -z "${METRON_JDBC_PASSWORD}" ]; then
+    echo "METRON_JDBC_PASSWORD unset. Exiting."
+    exit 1
+fi
+
+METRON_VERSION=${project.version}
+METRON_HOME="${METRON_HOME:-/usr/metron/${METRON_VERSION}}"
+HBASE_HOME=${HBASE_HOME:-/usr/hdp/current/hbase-client}
+METRON_REST_PORT=8082
+METRON_SYSCONFIG="${METRON_SYSCONFIG:-/etc/default/metron}"
+METRON_LOG_DIR="${METRON_LOG_DIR:-/var/log/metron}"
+METRON_PID_FILE="${METRON_PID_FILE:-/var/run/metron/metron-rest.pid}"
+
+echo "METRON_VERSION=${METRON_VERSION}"
+echo "METRON_HOME=${METRON_HOME}"
+echo "METRON_SYSCONFIG=${METRON_SYSCONFIG}"
+
+if [ -f "$METRON_SYSCONFIG" ]; then
+    echo "METRON_SYSCONFIG=${METRON_SYSCONFIG}"
+    set -a
+    . "$METRON_SYSCONFIG"
+fi
+
+METRON_REST_CLASSPATH="${METRON_REST_CLASSPATH:-$HADOOP_CONF_DIR:${HBASE_HOME}/conf}"
+
+# Use a custom REST jar if provided, else pull the metron-rest jar
+rest_jar_pattern="${METRON_HOME}/lib/metron-rest*.jar"
+rest_files=( ${rest_jar_pattern} )
+echo "Default metron-rest jar is: ${rest_files[0]}"
+METRON_REST_CLASSPATH+=":${rest_files[0]}"
+
+echo "METRON_SPRING_PROFILES_ACTIVE=${METRON_SPRING_PROFILES_ACTIVE}"
+
+# the vagrant Spring profile provides configuration values, otherwise configuration is provided
by rest_application.yml
+if [[ !(${METRON_SPRING_PROFILES_ACTIVE} == *"vagrant"*) ]]; then
+    METRON_CONFIG_LOCATION=" --spring.config.location=$METRON_HOME/config/rest_application.yml"
+    echo "METRON_CONFIG_LOCATION=${METRON_CONFIG_LOCATION}"
+    METRON_SPRING_OPTIONS+=${METRON_CONFIG_LOCATION}
+fi
+METRON_SPRING_OPTIONS+=" --server.port=$METRON_REST_PORT"
+if [ ${METRON_SPRING_PROFILES_ACTIVE} ]; then
+    METRON_PROFILES_ACTIVE=" --spring.profiles.active=${METRON_SPRING_PROFILES_ACTIVE}"
+    echo "METRON_PROFILES_ACTIVE=${METRON_PROFILES_ACTIVE}"
+    METRON_SPRING_OPTIONS+=${METRON_PROFILES_ACTIVE}
+fi
+
+if [ ${METRON_JDBC_CLIENT_PATH} ]; then
+    METRON_REST_CLASSPATH+=":${METRON_JDBC_CLIENT_PATH}"
+fi
+
+# Use a custom indexing jar if provided, else pull the metron-elasticsearch uber jar
+if [ ${METRON_INDEX_CP} ]; then
+    echo "Default metron indexing jar is: ${METRON_INDEX_CP}"
+    METRON_REST_CLASSPATH+=":${METRON_INDEX_CP}"
+else
+    indexing_jar_pattern="${METRON_HOME}/lib/metron-elasticsearch*uber.jar"
+    indexing_files=( ${indexing_jar_pattern} )
+    echo "Default metron indexing jar is: ${indexing_files[0]}"
+    METRON_REST_CLASSPATH+=":${indexing_files[0]}"
+fi
+
+echo "METRON_REST_CLASSPATH=${METRON_REST_CLASSPATH}"
+
+echo "Starting application"
+${JAVA_HOME}/bin/java ${METRON_JVMFLAGS} \
+-cp ${METRON_REST_CLASSPATH} \
+org.apache.metron.rest.MetronRestApplication \
+${METRON_SPRING_OPTIONS} >> ${METRON_LOG_DIR}/metron-rest.log 2>&1 & echo
$! > ${METRON_PID_FILE};


Mime
View raw message