Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Https port 155 #157

Open
wants to merge 11 commits into
base: unstable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ var start = function start(done) {
app._backlog = 2048;
apps.push(app);

var secureOptions;
var secureOptions, options;
dirModule = path.dirname(module.filename);
logger.info('config.enableSecure', config.enableSecure);

Expand All @@ -114,7 +114,7 @@ var start = function start(done) {
fs.statSync(secureOptions.key).isFile() &&
fs.statSync(secureOptions.cert).isFile()) {

var options = {
options = {
key: fs.readFileSync(secureOptions.key),
cert: fs.readFileSync(secureOptions.cert)
};
Expand All @@ -128,7 +128,7 @@ var start = function start(done) {
appSec.secOptions = options;
appSec.prefix = 'SEC:';
appSec.isSecure = true;
appSec.port = Number(config.agent.port) + 1;
appSec.port = Number(config.agent.httpsPort);

apps.push(appSec);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/baseConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ exports.logger = {};
exports.logger.logLevel = 'debug';
exports.logger.inspectDepth = 1;
exports.logger.Console = {
level: 'debug', timestamp: true
level: 'info', timestamp: true
};
exports.logger.File = {
level: 'debug', filename: dir_prefix +
Expand Down Expand Up @@ -179,6 +179,7 @@ exports.agent.maxMessages = 1000;
* @type {Number}
*/
exports.agent.port = 3001;
exports.agent.httpsPort = 3002;

/**
* Provision timeout
Expand Down
83 changes: 35 additions & 48 deletions lib/dataSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,57 +397,48 @@ var peek = function(appPrefix, queue, maxElems, callback) {
var queueId = queue.id,
fullQueueIdH = config.dbKeyQueuePrefix + 'H:' + appPrefix + queue.id,
fullQueueIdL = config.dbKeyQueuePrefix + 'L:' + appPrefix + queue.id,
restElems = 0;
restElems = 0,
db = dbCluster.getDb(queueId);

dbCluster.getOwnDb(queueId, function(err, db) {
if (err) {
manageError(err, callback);
} else {
peekAux(db);
}
});

function peekAux(db) {
db.lrange(fullQueueIdH, 0, maxElems - 1, function onRangeH(errH, dataH) {

var dataHlength = dataH.length;
if (errH) {//errH
manageError(errH, callback);
db.lrange(fullQueueIdH, 0, maxElems - 1, function onRangeH(errH, dataH) {

} else {
if (dataHlength < maxElems) {
var dataHlength = dataH.length;
if (errH) {//errH
manageError(errH, callback);

restElems = maxElems - dataHlength;
//Extract from both queues
db.lrange(fullQueueIdL, 0, restElems - 1,
function on_rangeL(errL, dataL) {
} else {
if (dataHlength < maxElems) {

if (errL) {
restElems = maxElems - dataHlength;
//Extract from both queues
db.lrange(fullQueueIdL, 0, restElems - 1,
function on_rangeL(errL, dataL) {

//fail but we may have data of previous range
if (dataH) {
//if there is dataH dismiss the low priority error
getPeekData(dataH, callback, queue);
} else {
manageError(errL, callback);
}
if (errL) {

//fail but we may have data of previous range
if (dataH) {
//if there is dataH dismiss the low priority error
getPeekData(dataH, callback, queue);
} else {
manageError(errL, callback);
}

if (dataL) {
dataH = dataH.concat(dataL);
}
} else {

getPeekData(dataH, callback, queue);
if (dataL) {
dataH = dataH.concat(dataL);
}
});
} else {
//just one queue used
getPeekData(dataH, callback, queue);
}

getPeekData(dataH, callback, queue);
}
});
} else {
//just one queue used
getPeekData(dataH, callback, queue);
}
});
}
}
});
};

function getPeekData(dataH, callback, queue) {
Expand Down Expand Up @@ -758,14 +749,10 @@ var repushUndeliveredTransaction = function(appPrefix, queue, priority, extTrans

var setBlockedQueue = function(appPrefix, queueId, blocked, cb) {

dbCluster.getOwnDb(queueId, function(err, db) {
if (err) {
manageError(err, cb);
} else {
var inc = blocked ? 1 : -1;
db.hincrby(config.dbKeyQueuePrefix + appPrefix + queueId + ':userInfo', 'blocked', inc, cb);
}
});
var inc = blocked ? 1 : -1,
db = dbCluster.getDb(queueId);

db.hincrby(config.dbKeyQueuePrefix + appPrefix + queueId + ':userInfo', 'blocked', inc, cb);
};

var ackTransaction = function ackTransaction(extTransactionId, queue, cb) {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
"hooker":"*",
"logger":"https://github.com/telefonicaid/pditclogger/tarball/master",
"performanceFramework":"https://github.com/PDI-DGS-Protolab/performanceFramework/tarball/master",
"should": "1.2.2",
"should": "1.2.2",
"forever": "0.10.8",
"daemon": "1.1.0",
"socket.io": "0.8.7",
"socket.io-client": "0.9.11"
},
Expand Down
99 changes: 99 additions & 0 deletions rpm/SOURCES/etc/init.d/pdi-popbox
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/bin/bash
# description: Script to wake up Agent.js from Popbox module
# chkconfig: 2345 85 11
###########################################
##Author: Carlos Enrique Gómez Gómez
##Depar: Release Engineering & Management
###########################################
## Values
# processname: popbox
# config: /opt/pdi-popbox/lib/baseConfig.js
# pidfile: /var/run/pdi-popbox/popbox.pid

source /etc/rc.d/init.d/functions

NAME=popbox
SOURCE_DIR=/opt/pdi-popbox/bin
SOURCE_FILE=popbox

user=popbox
pidfile=/var/run/pdi-popbox/$NAME.pid
logfile=/var/log/pdi-popbox/$NAME.log
forever_dir=/var/run/forever

node=node
sed=sed
home_dir="/opt/pdi-popbox"
forever=$home_dir/node_modules/forever/bin/forever

start() {
echo "Starting $NAME node instance: "

if [ "$foreverid" == "" ]; then
# Create the log and pid files, making sure that
# the target use has access to them
mkdir -p $(dirname $logfile)
touch $logfile
chown -R $user $(dirname $logfile)
mkdir -p $(dirname $pidfile)
#touch $pidfile
chown $user $(dirname $pidfile)

# Launch the application
cd $home_dir
daemon --user=$user \
$forever start -p $forever_dir --pidFile $pidfile -l $logfile -a \
$SOURCE_DIR/$SOURCE_FILE
RETVAL=$?
echo
else
echo "Instance already running"
RETVAL=0
echo
fi
}

stop() {
[ "$pid" == "" ] && return ;
echo "Shutting down $NAME(pid:$pid) node instance : "
processes=$(ps -ef|grep ^$user|grep $pid|grep -v "$home_dir/node_modules/forever"|awk '{print $2" "$3}' 2>/dev/null)
[ "$processes" == "" ] && echo "Any $user proccess is up" && RETVAL=1
if [ "$RETVAL" != "1" ]; then
kill -9 $processes
RETVAL=$?
fi
rm -Rf $pidfile
[ "$RETVAL" == "0" ] && echo_success
echo
}

if [ -f $pidfile ]; then
read pid < $pidfile
else
pid=""
fi
if [ "$pid" != "" ]; then
# Gnarly sed usage to obtain the foreverid.
sed1="/$pid\]/p"
sed2="s/.*\[\([0-9]\+\)\].*\s$pid\].*/\1/g"
foreverid=`$forever list -p $forever_dir | $sed -n $sed1 | $sed $sed2`
else
foreverid=""
fi

case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile}
;;
*)
echo "Usage: {start|stop|status}"
exit 1
;;
esac
exit $RETVAL
9 changes: 9 additions & 0 deletions rpm/SOURCES/etc/logrotate.d/pdi-popbox
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/var/log/popbox/*.log{
daily
rotate 10
copytruncate
delaycompress
compress
notifempty
missingok
}
112 changes: 112 additions & 0 deletions rpm/SPECS/popbox.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
Summary: Popbox module to manage node + Redis value server
Name: popbox
Version: 0.0.2
Release: 2
License: GNU
BuildRoot: %{_topdir}/BUILDROOT/
BuildArch: x86_64
Requires: nodejs >= 0.8
Requires(post): /sbin/chkconfig /usr/sbin/useradd
Requires(preun): /sbin/chkconfig, /sbin/service
Requires(postun): /sbin/service
Group: Applications/Popbox
Vendor: Telefonica I+D
BuildRequires: npm

%description
Simple High-Performance High-Scalability Inbox Notification Service,
require Redis 2.6 server, node 0.8 and npm only for installatión
%define _prefix_company pdi-
%define _project_name popbox
%define _project_user %{_project_name}
%define _company_project_name %{_prefix_company}%{_project_name}
%define _service_name %{_company_project_name}
%define _install_dir /opt
%define _srcdir %{_sourcedir}/../../
%define _project_install_dir %{_install_dir}/%{_company_project_name}
%define _logrotate_conf_dir %{_srcdir}/conf/log
%define _popbox_log_dir %{_localstatedir}/log/%{_company_project_name}
%define _build_root_project %{buildroot}/%{_project_install_dir}
%define _conf_dir /etc/%{_prefix_company}%{_project_name}
%define _log_dir /var/log/%{_prefix_company}%{_project_name}


# -------------------------------------------------------------------------------------------- #
# prep section, setup macro:
# -------------------------------------------------------------------------------------------- #
%prep
rm -Rf $RPM_BUILD_ROOT && mkdir -p $RPM_BUILD_ROOT
[ -d %{_build_root_project} ] || mkdir -p %{_build_root_project}

cp -R %{_srcdir}/lib %{_srcdir}/package.json %{_srcdir}/index.js \
%{_srcdir}/bin %{_srcdir}/License.txt %{_build_root_project}
cp -R %{_sourcedir}/* %{buildroot}
mkdir -p %{buildroot}/var/run/%{_company_project_name}
mkdir -p %{buildroot}/var/log/%{_company_project_name}

%build
cd %{_build_root_project}
# Only production modules
npm install --production
rm package.json

# -------------------------------------------------------------------------------------------- #
# pre-install section:
# -------------------------------------------------------------------------------------------- #
%pre
echo "[INFO] Creating %{_project_user} user"
grep ^%{_project_user} /etc/passwd
RET_VAL=$?
if [ "$RET_VAL" != "0" ]; then
/usr/sbin/useradd -c '%{_project_user}' -u 699 -s /bin/false \
-r -d %{_project_install_dir} %{_project_user}
RET_VAL=$?
if [ "$RET_VAL" != "0" ]; then
echo "[ERROR] Unable create popbox user" \
exit $RET_VAL
fi
fi

# -------------------------------------------------------------------------------------------- #
# post-install section:
# -------------------------------------------------------------------------------------------- #
%post
echo "Configuring application:"
rm -Rf /etc/initi.d/%{_service_name}
cd /etc/init.d

#Service
echo "Creating %{_service_name} service:"
chkconfig --add %{_service_name}

#Config
rm -Rf %{_conf_dir} && mkdir -p %{_conf_dir}
cd %{_conf_dir}
ln -s %{_project_install_dir}/lib/baseConfig.js %{_project_name}_conf.js

#Logs
#TODO configuration logs
echo "Done"

%preun
if [ $1 == 0 ]; then
echo "Removing application config files"
[ -d /etc/%{_company_project_name} ] && rm -rfv /etc/%{_company_project_name}
[ -d %{_popbox_log_dir} ] && rm -rfv %{_popbox_log_dir}
[ -d %{_project_install_dir} ] && rm -rfv %{_project_install_dir}
echo "Destroying %{_service_name} service:"
chkconfig --del %{_service_name}
rm -Rf /etc/init.d/%{_service_name}

echo "Done"
fi

%postun
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(755,%{_project_user},%{_project_user},755)
%config /etc/init.d/%{_service_name}
%config /etc/logrotate.d/%{_company_project_name}
%{_project_install_dir}
/var/
3 changes: 3 additions & 0 deletions rpm/package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
DIR=$(dirname $(readlink -f $0))
rpmbuild -v --clean -ba $DIR/SPECS/popbox.spec --define '_topdir '$DIR
Loading