Skip to content

Commit

Permalink
Merge pull request #52 from telefonicaid/hardening/service_configurat…
Browse files Browse the repository at this point in the history
…ion_file

Add service configuration file
  • Loading branch information
Fernando López Aguilar committed Sep 2, 2015
2 parents 510a5ce + 7e41159 commit 762663f
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 27 deletions.
5 changes: 4 additions & 1 deletion README.rst
Expand Up @@ -201,6 +201,9 @@ The configuration used by the adapter service is optionally read from the file

::

# ADAPTER_LOGFILE - Logging file
ADAPTER_LOGFILE=/var/log/ngsi_adapter/ngsi_adapter.log

# ADAPTER_LOGLEVEL - Logging level
ADAPTER_LOGLEVEL=INFO

Expand All @@ -217,7 +220,7 @@ The configuration used by the adapter service is optionally read from the file
ADAPTER_RETRIES=2


All these attributes map to options of the `command line interface
Most of these attributes map to options of the `command line interface
<doc/manuals/admin/README.rst#from-the-command-line>`_ as follows:

- ``ADAPTER_LOGLEVEL`` maps to ``-l`` or ``--logLevel`` option
Expand Down
4 changes: 4 additions & 0 deletions ngsi_adapter/README.rst
Expand Up @@ -22,6 +22,10 @@ Please refer to `this document </README.rst#running>`_ for details.
Changelog
=========

Version 1.2.4

- Add service configuration file

Version 1.2.3

- Fix problems when uninstalling package
Expand Down
6 changes: 6 additions & 0 deletions ngsi_adapter/script/build/files/debian/changelog
@@ -1,3 +1,9 @@
fiware-monitoring-ngsi-adapter (1.2.4) precise; urgency=low

* Add service configuration file

-- Telefónica I+D <opensource@tid.es> Fri, 14 Aug 2015 15:00:00 +0200

fiware-monitoring-ngsi-adapter (1.2.3) precise; urgency=low

* Fix problems when uninstalling package
Expand Down
17 changes: 17 additions & 0 deletions ngsi_adapter/script/build/files/debian/ngsi_adapter.default
@@ -0,0 +1,17 @@
# ADAPTER_LOGFILE - Logging file
ADAPTER_LOGFILE=#DH_LOGGING_DIR#/#DH_ADAPTER_SRV#.log

# ADAPTER_LOGLEVEL - Logging level
ADAPTER_LOGLEVEL=INFO

# ADAPTER_LISTEN_HOST - The host where NGSI Adapter listens to requests
ADAPTER_LISTEN_HOST=0.0.0.0

# ADAPTER_LISTEN_PORT - The port where NGSI Adapter listens to requests
ADAPTER_LISTEN_PORT=1337

# ADAPTER_BROKER_URL - The endpoint where Context Broker is listening
ADAPTER_BROKER_URL=http://127.0.0.1:1026/

# ADAPTER_RETRIES - Maximum number of retries invoking Context Broker
ADAPTER_RETRIES=2
10 changes: 6 additions & 4 deletions ngsi_adapter/script/build/files/debian/ngsi_adapter.init
@@ -1,4 +1,5 @@
#!/bin/sh
set -a

### BEGIN INIT INFO
# Provides: ngsi_adapter
Expand All @@ -14,13 +15,11 @@

PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="NGSI Adapter Service"
NAME=ngsi_adapter
NAME=#DH_ADAPTER_SRV#
DAEMON=#DH_FIWARE_DIR#/$NAME/adapter
DAEMON_ARGS=""
DAEMON_USER=fiware
PIDFILE=/var/run/$NAME.pid
LOGFILE=#DH_LOGGING_DIR#/$NAME.log
SCRIPTNAME=/etc/init.d/$NAME

# Exit if the component is not installed
[ -x "$DAEMON" ] || exit 0
Expand All @@ -29,6 +28,9 @@ SCRIPTNAME=/etc/init.d/$NAME
[ -r /etc/profile ] && . /etc/profile
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Setup daemon logging according to configuration variables
LOGFILE=${ADAPTER_LOGFILE:-#DH_LOGGING_DIR#/$NAME.log}

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

Expand Down Expand Up @@ -122,7 +124,7 @@ case "$1" in
status_of_proc -p"$PIDFILE" "$DAEMON" "$NAME" && exit 0 || exit $?
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|status}" >&2
echo "Usage: service $NAME {start|stop|restart|status}" >&2
exit 3
;;
esac
Expand Down
5 changes: 2 additions & 3 deletions ngsi_adapter/script/build/files/debian/postinst
Expand Up @@ -64,9 +64,8 @@ if [ "$1" = configure ]; then
NGSI Adapter successfully installed at $ADAPTER_DIR.
WARNING: Check configuration file $ADAPTER_DIR/config/options.js
and logging parameters at /etc/init.d/$ADAPTER_SRV before
starting \`$ADAPTER_SRV' service. This component DOES NOT
WARNING: Check configuration file /etc/default/$ADAPTER_SRV
before starting \`$ADAPTER_SRV' service. This component DOES NOT
rotate logging files, so consider configuring \`logrotate'
or similar. Please read Usage section at README.rst for more
details.
Expand Down
4 changes: 4 additions & 0 deletions ngsi_adapter/script/build/files/debian/rules
Expand Up @@ -34,6 +34,10 @@ override_dh_install:
$(foreach var,$(DH_VARS),$(call dh_var_subst,$(var),debian/postinst))
$(foreach var,$(DH_VARS),$(call dh_var_subst,$(var),debian/postrm))
$(foreach var,$(DH_VARS),$(call dh_var_subst,$(var),debian/$(DH_ADAPTER_SRV).init))
$(foreach var,$(DH_VARS),$(call dh_var_subst,$(var),debian/$(DH_ADAPTER_SRV).default))

override_dh_installinit:
dh_installinit --name=$(DH_ADAPTER_SRV) --no-start

override_dh_shlibdeps:
dh_shlibdeps --dpkg-shlibdeps-params=--ignore-missing-info
13 changes: 5 additions & 8 deletions ngsi_adapter/script/build/files/redhat/SOURCES/etc/init.d/ngsi_adapter 100644 → 100755
@@ -1,9 +1,5 @@
#!/bin/sh
#
# chkconfig: 2345 91 10
# description: NGSI Adapter is a generic component to transform monitoring \
# data from probes to NGSI context attributes, and forward \
# them through a NGSI Context Broker.
set -a

### BEGIN INIT INFO
# Provides: ngsi_adapter
Expand All @@ -24,8 +20,6 @@ DAEMON=/opt/fiware/$NAME/adapter
DAEMON_ARGS=""
DAEMON_USER=fiware
PIDFILE=/var/run/$NAME.pid
LOGFILE=/var/log/$NAME/$NAME.log
SCRIPTNAME=/etc/init.d/$NAME

# Exit if the component is not installed
[ -x "$DAEMON" ] || exit 0
Expand All @@ -34,6 +28,9 @@ SCRIPTNAME=/etc/init.d/$NAME
[ -r /etc/profile ] && . /etc/profile
[ -r /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME

# Setup daemon logging according to configuration variables
LOGFILE=${ADAPTER_LOGFILE:-/var/log/$NAME/$NAME.log}

# Check that networking is up
[ -r /etc/sysconfig/network ] && . /etc/sysconfig/network
[ "${NETWORKING}" = "no" ] && exit 0
Expand Down Expand Up @@ -97,7 +94,7 @@ case "$1" in
status -p $PIDFILE $NAME
;;
*)
echo $"Usage: $NAME {start|stop|restart|status}" >&2
echo $"Usage: service $NAME {start|stop|restart|status}" >&2
exit 3
;;
esac
Expand Down
@@ -0,0 +1,17 @@
# ADAPTER_LOGFILE - Logging file
ADAPTER_LOGFILE=/var/log/ngsi_adapter/ngsi_adapter.log

# ADAPTER_LOGLEVEL - Logging level
ADAPTER_LOGLEVEL=INFO

# ADAPTER_LISTEN_HOST - The host where NGSI Adapter listens to requests
ADAPTER_LISTEN_HOST=0.0.0.0

# ADAPTER_LISTEN_PORT - The port where NGSI Adapter listens to requests
ADAPTER_LISTEN_PORT=1337

# ADAPTER_BROKER_URL - The endpoint where Context Broker is listening
ADAPTER_BROKER_URL=http://127.0.0.1:1026/

# ADAPTER_RETRIES - Maximum number of retries invoking Context Broker
ADAPTER_RETRIES=2
Expand Up @@ -47,6 +47,7 @@ cp -R %{_sourcedir}/* $RPM_BUILD_ROOT
echo "FILES:"; cat %{_topdir}/MANIFEST

%files -f %{_topdir}/MANIFEST
%config /etc/sysconfig/%{_adapter_srv}

%pre
# preinst ($1 == 1)
Expand Down Expand Up @@ -153,9 +154,8 @@ if [ $1 -eq 1 ]; then
NGSI Adapter successfully installed at $ADAPTER_DIR.
WARNING: Check configuration file $ADAPTER_DIR/config/options.js
and logging parameters at /etc/init.d/$ADAPTER_SRV before
starting \`$ADAPTER_SRV' service. This component DOES NOT
WARNING: Check configuration file /etc/sysconfig/$ADAPTER_SRV
before starting \`$ADAPTER_SRV' service. This component DOES NOT
rotate logging files, so consider configuring \`logrotate'
or similar. Please read Usage section at README.rst for more
details.
Expand Down Expand Up @@ -187,6 +187,9 @@ if [ $1 -eq 0 ]; then
fi

%changelog
* Fri Aug 14 2015 Telefónica I+D <opensource@tid.es> 1.2.4-1
- Add service configuration file

* Fri Mar 27 2015 Telefónica I+D <opensource@tid.es> 1.2.3-1
- Fix problems when uninstalling package

Expand Down
2 changes: 1 addition & 1 deletion ngsi_adapter/script/build/package.sh
Expand Up @@ -75,7 +75,7 @@ create_deb_package() {
cp -r $PROGDIR/files/debian $BASEDIR
cd $BASEDIR
[ -n "$VERSION" ] && debchange -M -v "$VERSION" "$CHANGELOG"
dpkg-buildpackage -b -rfakeroot -D -us -uc \
dpkg-buildpackage -b -rfakeroot -D -d -us -uc \
&& dpkg_files=$(ls -t ../*.deb ../*.changes 2>/dev/null | head -2) \
&& package=$(expr "$dpkg_files" : ".*/\(.*\.deb\)") \
&& mv -f $dpkg_files $BASEDIR \
Expand Down
31 changes: 25 additions & 6 deletions ngsi_adapter/src/config/options.js
Expand Up @@ -54,12 +54,31 @@ var defaults = {
* @property {Number} opts.retries Maximum number of invocation retries.
*/
var opts = require('optimist')
.options('l', { alias: 'logLevel', 'default': defaults.logLevel, describe: 'Logging level' })
.options('b', { alias: 'brokerUrl', 'default': defaults.brokerUrl, describe: 'Context Broker URL' })
.options('H', { alias: 'listenHost', 'default': defaults.listenHost, describe: 'Adapter listen host' })
.options('p', { alias: 'listenPort', 'default': defaults.listenPort, describe: 'Adapter listen port' })
.options('r', { alias: 'retries', 'default': defaults.retries, describe: 'Maximum retries' })
.options('h', { alias: 'help', 'boolean': true, describe: 'Show help' })
.options('l', {
alias: 'logLevel',
'default': process.env['ADAPTER_LOGLEVEL'] || defaults.logLevel,
describe: 'Logging level'
}).options('H', {
alias: 'listenHost',
'default': process.env['ADAPTER_LISTEN_HOST'] || defaults.listenHost,
describe: 'Adapter listen host'
}).options('p', {
alias: 'listenPort',
'default': process.env['ADAPTER_LISTEN_PORT'] || defaults.listenPort,
describe: 'Adapter listen port'
}).options('b', {
alias: 'brokerUrl',
'default': process.env['ADAPTER_BROKER_URL'] || defaults.brokerUrl,
describe: 'Context Broker URL'
}).options('r', {
alias: 'retries',
'default': process.env['ADAPTER_RETRIES'] || defaults.retries,
describe: 'Maximum retries'
}).options('h', {
alias: 'help',
'boolean': true,
describe: 'Show help'
})
.demand([]);


Expand Down
2 changes: 1 addition & 1 deletion ngsi_adapter/src/package.json
@@ -1,5 +1,5 @@
{
"version": "1.3.1",
"version": "1.2.4",
"name": "ngsi_adapter",
"description": "Generic NGSI Probe Adapter",
"product": {
Expand Down

0 comments on commit 762663f

Please sign in to comment.