Skip to content

Commit

Permalink
Merge pull request #158 from CodeforAustralia/fix/server-config
Browse files Browse the repository at this point in the history
Fix server config
  • Loading branch information
more-like-a-puma committed Sep 29, 2016
2 parents 381b4ab + f0c8362 commit 5dec4e0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Makefile
Expand Up @@ -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
Expand Down
41 changes: 41 additions & 0 deletions 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

0 comments on commit 5dec4e0

Please sign in to comment.