From fe5a32153df0b04f0989f441843bda0977505af7 Mon Sep 17 00:00:00 2001 From: Peter W Date: Wed, 28 Sep 2016 20:46:14 +1300 Subject: [PATCH 1/2] Added Upstart config file for server --- server/heritage-api.conf | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 server/heritage-api.conf diff --git a/server/heritage-api.conf b/server/heritage-api.conf new file mode 100644 index 0000000..791514d --- /dev/null +++ b/server/heritage-api.conf @@ -0,0 +1,41 @@ +# heritage-api - Start PostgREST API service for Heritage Near Me +# This is an upstart config file for Linux; it goes in /etc/init +# Read more: +# * https://www.digitalocean.com/community/tutorials/the-upstart-event-system-what-it-is-and-how-to-use-it +# * https://www.digitalocean.com/community/tutorials/how-to-configure-a-linux-service-to-start-automatically-after-a-crash-or-reboot-part-1-practical-examples + +# +# Note: when installing this, run this as root before running the service: +# +# touch /var/log/heritage-api.log +# chown postgres /var/log/heritage-api.log +# mkdir -p /var/run/heritage +# chown postgres /var/run/heritage + + +description "Start Heritage Near Me API (PostgREST)" +author "Peter W (@techieshark)" + +start on filesystem or runlevel [2345] +stop on shutdown + +# Run as "postgres" user since that has correct access to database +setuid postgres + +script + + echo $$ > /var/run/heritage-api.pid + exec postgrest postgres://localhost:5432/hnm --port 3000 --schema hnm --anonymous postgres --pool 200 > /var/log/heritage-api.log + +end script + + +pre-start script + echo "[`date`] Heritage API Starting" >> /var/log/heritage-api.log +end script + + +pre-stop script + rm /var/run/heritage-api.pid + echo "[`date`] Heritage API Stopping" >> /var/log/heritage-api.log +end script From f0c83624224cbedc37ab3c2d3d29632678a3a886 Mon Sep 17 00:00:00 2001 From: Peter W Date: Wed, 28 Sep 2016 20:48:41 +1300 Subject: [PATCH 2/2] update makefile for changes to API service start method * add target to install service config for Upstart based servers * change other target so we don't use the dumb screen method that wasn't working (running screen in combo with changing users via sudo wasn't working) --- Makefile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index f152af8..5eddb5d 100644 --- a/Makefile +++ b/Makefile @@ -20,10 +20,15 @@ server-dbinit: server-dropdb: su postgres -c "dropdb --if-exists $(DB)" -RUN_API="postgrest postgres://localhost:5432/hnm --port 3000 --schema hnm --anonymous $(DB_USER) --pool 200" +server-install-api-service: + sudo touch /var/log/heritage-api.log + sudo chown postgres /var/log/heritage-api.log + sudo mkdir -p /var/run/heritage + sudo chown postgres /var/run/heritage + sudo cp server/heritage-api.conf /etc/init server-apistart: - screen -S hnm-api -d -m $(RUN_API) + sudo service heritage-api start server-update-from-git: git pull