diff --git a/Makefile b/Makefile index bff3007..b396a7b 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,11 @@ +################################################################################ +# Change eth0 to your interface +################################################################################ + +INTERFACE = eth0 + +################################################################################ + LOG = server.log SERVER = server.js BLENDER_VER = "2.74" @@ -8,6 +16,8 @@ CACHE += "./events.log" CACHE += "./server.log" DONE = [\33[32;5mFinalizado\33[m] FAIL = [\33[31;5mFalhou\33[m] Codigo: $$? +INIT_SCRIPT = "wikilibras-api.init" +LOCALHOST = $(shell ip addr list ${INTERFACE} | grep "inet " | cut -d ' ' -f6 | cut -d/ -f1) __help__: @echo "" @@ -19,23 +29,36 @@ __help__: @echo " \33[32;5m make stop \33[0m \33[34;5m finaliza a API instanciada no background \33[0m" @echo "" +startup-enable: + @sed "s##$(CURDIR)#" ./$(INIT_SCRIPT) | sudo tee /etc/init.d/$(INIT_SCRIPT) + @sudo chmod 755 /etc/init.d/$(INIT_SCRIPT) + @sudo chown "root:root" /etc/init.d/$(INIT_SCRIPT) + @sudo update-rc.d -f $(INIT_SCRIPT) defaults + +startup-disable: + @sudo update-rc.d -f $(INIT_SCRIPT) remove + @sudo rm -f /etc/init.d/$(INIT_SCRIPT) + clean: @rm -rf $(CACHE) -install: uninstall .update .blender .libav .nodejs .npm .mongodb +install: uninstall .update .blender .libav .nodejs .npm .mongodb update-ip @echo "\33[31;5mO computador deve ser reiniciado para concluir o processo\33[0m" -uninstall: clean +uninstall: clean startup-disable @sudo rm -rf "./node_modules" @sudo rm -f "./wikilibras_server" @sudo rm -rf "./node_modules" + @sudo rm -rf "$$HOME/.forever" + @sudo rm -rf "$$HOME/.node-gyp" + @sudo rm -rf "$$HOME/.npm" .blender: @sudo apt-get -y install blender @test -d "/usr/share/blender$(BLENDER_VER)/" || make -s .blender_stable .blender_stable: - @wget $(BLENDER_URL) -NcO ""$$HOME"/$(BLENDER_DIR).tar.bz2" + @wget $(BLENDER_URL) -NcO "$$HOME/$(BLENDER_DIR).tar.bz2" @cd "$$HOME" && \ tar -xf $(BLENDER_BZ2) && \ sudo rm -rf "/usr/share/blender$(BLENDER_VER)/" && \ @@ -65,6 +88,13 @@ uninstall: clean @sudo npm link forever node-gyp cors @sudo npm install +update-ip: + @cp helpers/properties.js.template helpers/properties.js + @sed -e '/^var host/{s/.*/var host = \"localhost\";/}' -i "./helpers/properties.js" + @if [ "${LOCALHOST}" != "" ]; then sed -e '/^var host/{s/.*/var host = \"${LOCALHOST}\";/}' -i "./helpers/properties.js"; fi + @cat "./helpers/properties.js" | grep "var host" + @cat "./helpers/properties.js" | grep "var port" + .update: @sudo apt-get update @@ -76,6 +106,8 @@ run: start: @forever start --spinSleepTime 1000 --minUptime 1000 -a -l $(LOG) -o $(LOG) -e $(LOG) $(SERVER) + @echo "`date` Service started ... " >> $(LOG) stop: @forever stop $(SERVER) + @echo "`date` Service stopped ... " >> $(LOG) diff --git a/wikilibras-api.init b/wikilibras-api.init new file mode 100755 index 0000000..af7a757 --- /dev/null +++ b/wikilibras-api.init @@ -0,0 +1,46 @@ +#!/bin/sh + +### BEGIN INIT INFO +# Provides: wikilibras-api +# Required-Start: $all +# Required-Stop: $all +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Run API for Wikilibras API +# Description: Enable service provided by Wikilibras API at boot +### END INIT INFO + +set -e + +export PATH=$PATH:/usr/local/bin + +CWD="" + +case "$1" in + start) + cd "$CWD" + make start + ;; + stop) + cd "$CWD" + make stop + ;; + *) + echo "Usage: /etc/init.d/wikilibras-api.init {start|stop}" + exit 1 + ;; +esac + +exit 0 + +#startup-enable: +# @sudo cp ./wikilibras-api.init /etc/init.d/wikilibras-api.init +# @sudo chmod 755 /etc/init.d/wikilibras-api.init +# @sudo chown "root:root" /etc/init.d/wikilibras-api.init +# @sudo update-rc.d -f wikilibras-api.init defaults + +#startup-disable: +# @sudo update-rc.d -f wikilibras-api.init remove +# @sudo rm -f /etc/init.d/wikilibras-api.init + + -- libgit2 0.21.2