Skip to content

Commit

Permalink
adicion de servicio para RHEL 7
Browse files Browse the repository at this point in the history
  • Loading branch information
themonki committed Feb 4, 2016
1 parent fb37656 commit 1eaa74a
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 1 deletion.
17 changes: 17 additions & 0 deletions packageRHEL.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export JAVA_HOME=/usr/local/java/jdk8

rm -rf build

mkdir -p build/resources

cp serviceRHEL/* build/

mvn clean

mvn package

cp target/GtfsrtExporter-0.0.1-SNAPSHOT.jar build/GtfsrtExpo.jar

cp src/main/resources/usage.txt build/

cp src/main/resources/config.properties build/resources/
2 changes: 1 addition & 1 deletion serviceLin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ DAEMON_NAME_DISTRO=""
DAEMON_DEBIAN=$(DAEMON_NAME)-deb
DISTRO_DEBIAN=$(shell cat /etc/*-release | grep -i -E "ubuntu" | head -1)
DAEMON_REDHAT=$(DAEMON_NAME)-epel
DISTRO_REDHAT=$(shell cat /etc/*-release | grep -i -E "centos|redhat" | head -1)
DISTRO_REDHAT=$(shell cat /etc/*-release | grep -i -E "centos|red hat" | head -1)

all: install

Expand Down
108 changes: 108 additions & 0 deletions serviceRHEL/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Makefile para instalar dmGtfsrtExpo para systemd
# Edgar Moncada
# Create 05-01-2016
# Ejecutar solo como root

COMMON_NAME=GtfsrtExpo

INSTALL_PATH=/usr/local/$(COMMON_NAME)
CONFIG_PATH=/usr/local/etc/$(COMMON_NAME)
DAEMON_NAME=dm$(COMMON_NAME)
SERVICE_PATH=/etc/systemd/system/$(DAEMON_NAME).service
JAR_NAME=$(COMMON_NAME).jar
RES_PATH=resources
RUN_USER=$(USER)
$(eval IS_PRINT_ERROR := true)

#dependiendo de la distribucion almacena y configura el demonio
DAEMON_REDHAT=$(DAEMON_NAME).service
DISTRO_REDHAT=$(shell cat /etc/*-release | grep -i -E "centos|red hat" | head -1)

all: install

install: remove
ifeq "root" "$(RUN_USER)"
$(call blockInstall)
else
$(call printerror)
endif

remove:
ifeq "root" "$(RUN_USER)"
$(call blockRemove)
else
$(call printerror)
endif

purge: remove
ifeq "root" "$(RUN_USER)"
$(call blockPurge)
else
$(call printerror)
endif

rundaemon:
ifeq "root" "$(RUN_USER)"
$(call blockRundaemon)
else
$(call printerror)
endif

installandrun: install rundaemon

define printerror
@if $(IS_PRINT_ERROR); then echo "No es usuario root, saliendo."; fi
$(eval IS_PRINT_ERROR := false)
endef

define blockInstall
@echo ""
@echo "Instalando ..."
@echo ""
mkdir -p $(INSTALL_PATH);
cp -R $(DAEMON_NAME).sh usage.txt $(JAR_NAME) $(INSTALL_PATH);
@if [ ! -z "$(DISTRO_REDHAT)" ]; then cp $(DAEMON_REDHAT) $(SERVICE_PATH); echo "cp $(DAEMON_REDHAT) $(SERVICE_PATH)"; fi
chmod +x $(INSTALL_PATH)/$(DAEMON_NAME).sh;
# chmod 755 $(SERVICE_PATH);
ln -s $(INSTALL_PATH)/$(DAEMON_NAME).sh /usr/bin/$(DAEMON_NAME).sh;
@if [ ! -d $(CONFIG_PATH) ]; then mkdir -p $(CONFIG_PATH); echo "mkdir -p $(CONFIG_PATH)"; cp -R $(RES_PATH) $(CONFIG_PATH); echo "cp -R $(RES_PATH) $(CONFIG_PATH)"; else echo "Existe el directorio $(CONFIG_PATH)";fi
@if [ -f "$(CONFIG_PATH)/$(RES_PATH)/config.properties" ]; then echo "Existe archivo de configuracion $(CONFIG_PATH)/$(RES_PATH)/config.properties. No se reemplaza"; else if [ ! -f $(RES_PATH)/config.properties ]; then echo "Warning: no existe archivo $(CONFIG_PATH)/$(RES_PATH)/config.properties."; fi ; fi
@if [ ! -f "$(CONFIG_PATH)/$(RES_PATH)/config.properties" ] && [ -f $(RES_PATH)/config.properties ]; then cp $(RES_PATH)/config.properties $(CONFIG_PATH)/$(RES_PATH); echo "cp $(RES_PATH)/config.properties $(CONFIG_PATH)/$(RES_PATH)"; fi;
@echo ""
@echo "Instalado"
@echo "Revisar que exista el archivo $(CONFIG_PATH)/$(RES_PATH)/config.properties y este configurado adecuadamente."
@echo "El log se almacenara en $(INSTALL_PATH)"
@echo ""
endef

define blockRundaemon
@if [ -f "$(SERVICE_PATH)" ] && [ ! -z "$(DISTRO_REDHAT)" ]; then systemctl daemon-reload; echo "systemctl daemon-reload"; systemctl start $(DAEMON_REDHAT); echo "systemctl start $(DAEMON_REDHAT)"; systemctl enable $(DAEMON_REDHAT); echo "systemctl enable $(DAEMON_REDHAT)"; fi
@if [ -f "$(SERVICE_PATH)" ] && [ ! -z "$(DISTRO_REDHAT)" ]; then echo ""; echo "Autoarranque e iniciando el demonio $(DAEMON_NAME)."; echo ""; fi
endef


define blockRemove
@echo ""
@echo "Removiendo ..."
@echo ""
@echo "deteniendo servicio ..."
@if [ -f $(SERVICE_PATH) ] && [ ! -z "$(DISTRO_REDHAT)" ]; then systemctl stop $(DAEMON_REDHAT); echo "systemctl stop $(DAEMON_REDHAT)"; fi
@echo "detenido ..."
@if [ -f $(SERVICE_PATH) ] && [ ! -z "$(DISTRO_REDHAT)" ]; then systemctl disable $(DAEMON_REDHAT); echo "systemctl disable $(DAEMON_REDHAT)"; fi
rm -rf $(INSTALL_PATH) $(SERVICE_PATH) /usr/bin/$(DAEMON_NAME).sh
@echo ""
@echo "Removido el componente en $(INSTALL_PATH) y $(SERVICE_PATH)."
@echo ""
endef

define blockPurge
@echo ""
@echo "Purgando ..."
@echo ""
rm -rf $(CONFIG_PATH)
@echo ""
@echo "Eliminados archivos de configuracion en $(CONFIG_PATH)."
@echo ""
endef


11 changes: 11 additions & 0 deletions serviceRHEL/dmGtfsrtExpo.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=Exportador creador de URL de Gtfs-realtime para datos del MIO
After=network-online.target

[Service]
ExecStart=/usr/bin/dmGtfsrtExpo.sh exec
Restart=on-failure
RestartSec=10s

[Install]
WantedBy=multi-user.target
76 changes: 76 additions & 0 deletions serviceRHEL/dmGtfsrtExpo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/bin/bash
# -*- mode: sh -*-
# vi: set ft=sh :


##
# construye los comandos necesarios para ejecucion del demonio:
# si se pasa como parametro java devuelve el jdk a utilizar, si esta instanciado
# en orden JAVA_8_HOME, JAVA_HOME si no estan instanciadas entonces se toma /usr/local/java/jdk.
# si se pasa como parametro args devuelve los argumentos necesarios para ejecutar.
# si se pasa comand devuelve el comando usual
##

#cambiar de acuerdo al Makefile
COMMON_NAME=GtfsrtExpo
DESC="Exportador creador de URL para Gtfs-realtime"

#Si se usa symbol link
WORK_PATH="/usr/local/$COMMON_NAME"
cd "$WORK_PATH"

CONFIG_PATH=/usr/local/etc/$COMMON_NAME/resources
FILE_JAR="$COMMON_NAME.jar"
JVM_ARGS="-Xms30m -Xmx50m"
LOG_ARG=""
FILE_ARGS="--vehiclePositionsPathRead=/media/bpfiles/vehiclePositions.pb --tripUpdatesPathRead=/media/bpfiles/tripUpdates.pb --alertsPathRead=/media/bpfiles/alerts.pb"
URL_ARGS="--alertsUrl=http://localhost:8082/alerts --tripUpdatesUrl=http://localhost:8082/trip-updates --vehiclePositionsUrl=http://localhost:8082/vehicle-positions"
EXPO_ARGS="--vehiclePositionsPath=/var/www/html/gtfs/realtime/vehiclePositions.pb --tripUpdatesPath=/var/www/html/gtfs/realtime/tripUpdates.pb --alertsPath=/var/www/html/gtfs/realtime/alerts.pb"
REFR_ARGS="--refreshInterval=10"
CONFIG_ARG="$CONFIG_PATH/config.properties"

if [ ! -z "$JAVA_8_HOME" ]; then
JAVA_HOME="$JAVA_8_HOME"
else
if [ -z "$JAVA_HOME" ]; then
JAVA_HOME="/usr/local/java/jdk8"
fi
fi

JAVA_BIN="$JAVA_HOME/bin/java"

ARGS="$JVM_ARGS $LOG_ARG -jar $FILE_JAR $FILE_ARGS $URL_ARGS $EXPO_ARGS $REFR_ARGS $CONFIG_ARG"

COMAND="$JAVA_BIN $ARGS"

if [ "$1" = "java" ]; then
echo $JAVA_BIN
fi

if [ "$1" = "args" ]; then
echo $ARGS
fi

if [ "$1" = "comand" ]; then
echo $COMAND
fi

if [ "$1" = "desc" ]; then
echo $DESC
fi

function handle_sigint()
{
echo -n "Kill subproces PID $!"
kill -1 $!
}

##Ejecutar el comando
##Capturar señales de interrupcion
if [ "$1" = "exec" ]; then
trap handle_sigint SIGHUP SIGINT SIGTERM SIGKILL
$COMAND &
wait
fi

exit 0

0 comments on commit 1eaa74a

Please sign in to comment.