Skip to content

Instantly share code, notes, and snippets.

@psychemedia
Last active July 13, 2020 17:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save psychemedia/f256960c112347dd410c2beec8ce05e3 to your computer and use it in GitHub Desktop.
Save psychemedia/f256960c112347dd410c2beec8ce05e3 to your computer and use it in GitHub Desktop.
Simple user_data script for getting an authenticated OpenRefine server running on Digital Ocean
#!/bin/bash
USER_NAME=${USER_NAME:-test}
USER_PWD=${USER_NAME:-letmein}
apt-get update && apt-get install -y nginx apache2-utils
htpasswd -b -c /etc/nginx/.htpasswd $USER_NAME $USER_PWD
sudo ufw allow 'Nginx Full'
#Create a simple homepage
mkdir -p /var/www/html
echo """
<html>
<meta http-equiv="refresh" content="5" >
<head><title>OpenRefine Online</title></head>
<body>
<h1>OpenRefine Online</h1>
<p>Waiting for service to arrive...</p>
</body>
</html>
""" > /var/www/html/index.html
echo """
server {
listen 80;
auth_basic Protected...;
auth_basic_user_file /etc/nginx/.htpasswd;
location / {
root /var/www/html ;
index index.html;
auth_basic off;
}
}
""" > /etc/nginx/sites-available/default
nginx -s reload
apt-get install -y openjdk-8-jre
wget -q -O openrefine-2.8.tar.gz https://github.com/OpenRefine/OpenRefine/releases/download/2.8/openrefine-linux-2.8.tar.gz
#Unpack into /opt/openrefine-2.8
tar xzf openrefine-2.8.tar.gz -C /opt
OPENREFINE_USER=openrefine
OPENREFINE_PORT=3333
OPENREFINE_DIR="/opt/openrefine/projects"
mkdir -p $OPENREFINE_DIR
#Create a system user (no login or home directory)
useradd -r $OPENREFINE_USER
echo """
[Unit]
Description=OpenRefine
#When to bring the service up
#Wait for a network stack to appear
After=network.target
[Service]
User=$OPENREFINE_USER
Environment=REFINE_HOST=0.0.0.0
ExecStart=/opt/openrefine-2.8/refine -p $OPENREFINE_PORT -d $OPENREFINE_DIR
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
""" >> /lib/systemd/system/refine.service
# Enable autostart
systemctl enable refine.service
# Refresh service config
systemctl daemon-reload
#Get service going
service refine restart
#Update the nginx proxy
#It should be possible to just add another site config file
# rather than redo the whole script?
echo """
server {
listen 80;
auth_basic Protected...;
auth_basic_user_file /etc/nginx/.htpasswd;
location / {
root /var/www/html ;
index index.html;
auth_basic off;
}
location /openrefine/ {
proxy_pass http://127.0.0.1:3333/;
}
}
""" > /etc/nginx/sites-available/default
echo """
<html>
<head><title>OpenRefine Online</title></head>
<body>
<h1>OpenRefine Online</h1>
<p>Find the server <a href="./openrefine">here</a> (authentication required)</p>
</body>
</html>
""" > /var/www/html/index.html
nginx -s reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment