From ba8b70354345cc67b8d0ec0063aa92bb0af3ba47 Mon Sep 17 00:00:00 2001 From: Paul Liverman III Date: Tue, 24 Apr 2018 06:00:58 -0700 Subject: [PATCH] corrected typo in api, install script fixed/supports dev option --- applications/api.moon | 2 +- install.sh | 50 +++++++++++++++++++++++++------------------ 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/applications/api.moon b/applications/api.moon index a22738a..4c361c5 100644 --- a/applications/api.moon +++ b/applications/api.moon @@ -104,7 +104,7 @@ class API extends Application -- return json: { success: true, task: tasks[1] } -- else -- return standard_err! - return status: 501 json: { errors: {"Not implemented."} } + return status: 501, json: { errors: {"Not implemented."} } [list: "/list"]: capture_errors_json json_params => assert_valid @params, { diff --git a/install.sh b/install.sh index c98a02b..c765d03 100755 --- a/install.sh +++ b/install.sh @@ -7,11 +7,15 @@ OPENRESTY_VERSION=1.13.6.1 LUAROCKS_VERSION=2.4.1 POSTGRES_PASSWORD=$(cat /dev/urandom | head -c 12 | base64) -read -p "Enter email address for use with certbot-auto: " EMAIL_ADDRESS -read -p "Enter the domain name this will be running on: " DOMAIN_NAME -read -p "Enter the port this will be running on: " PORT +if [ $1 != "dev" ] +then + read -p "Enter email address for use with certbot-auto: " EMAIL_ADDRESS + read -p "Enter the domain name this will be running on: " DOMAIN_NAME + read -p "Enter the port this will be running on: " PORT +fi EMAIL_ADDRESS=${EMAIL_ADDRESS:-noone@example.com} +DOMAIN_NAME=${DOMAIN_NAME:-localhost} PORT=${PORT:-9872} ### PREREQUISITES ### @@ -21,7 +25,7 @@ then sudo apt-get install nginx -y fi -if ! command -v certbot-auto >/dev/null 2>&1 +if ! command -v certbot-auto >/dev/null 2>&1 && [ $1 != "dev" ] then wget https://dl.eff.org/certbot-auto chmod a+x ./certbot-auto @@ -33,7 +37,7 @@ then sudo apt-get install postgresql -y fi -if ! command -v openresty >/dev/null 2>&1 || [ ! -d '/usr/loca/openresty' ] +if ! command -v openresty >/dev/null 2>&1 || [ ! -d '/usr/local/openresty' ] then sudo apt-get install wget curl lua5.1 liblua5.1-0-dev zip unzip libreadline-dev libncurses5-dev libpcre3-dev openssl libssl-dev perl make build-essential -y cd .. @@ -63,17 +67,20 @@ then cd $INSTALL_DIR fi -sudo luarocks install luacrypto # needed for lapis, but lapis doesn't install it +sudo luarocks install luacrypto # needed for pgmoon, but not installed automatically ? sudo luarocks install lapis sudo luarocks install moonscript sudo luarocks install bcrypt sudo luarocks install lapis-console # not used yet, but I totally will # Certificate / TLS Security -sudo nginx -s stop -sudo certbot-auto certonly --standalone --agree-tos -m $EMAIL_ADDRESS -d $DOMAIN_NAME -sudo nginx -openssl dhparam -out ./dhparams.pem 2048 +if [ $1 != "dev" ] +then + sudo nginx -s stop + sudo certbot-auto certonly --standalone --agree-tos -m $EMAIL_ADDRESS -d $DOMAIN_NAME + sudo nginx + openssl dhparam -out ./dhparams.pem 2048 +fi # Database access sudo -u postgres createuser simplex @@ -88,12 +95,15 @@ echo "{ _port: $PORT }" > ./secret.moon -# Compile, Run migrations +# Compile, Change owner, Run migrations moonc . +sudo chown -R www-data:www-data ./ lapis migrate production # As-a-Service -sudo echo "[Unit] +if [ $1 != "dev" ] +then + sudo echo "[Unit] Description=simplex server [Service] @@ -106,11 +116,12 @@ ExecStop=$(which lapis) term [Install] WantedBy=multi-user.target" > /etc/systemd/system/simplex.service -sudo systemctl daemon-reload -sudo systemctl enable simplex.service + sudo systemctl daemon-reload + sudo systemctl enable simplex.service + sudo service simplex start -# Proxy -sudo echo "server { + # Proxy + sudo echo "server { listen 443 ssl; server_name $DOMAIN_NAME; @@ -134,8 +145,5 @@ sudo echo "server { proxy_pass http://127.0.0.1:$PORT; } }" > /etc/nginx/sites-enabled/simplex-proxy.conf -sudo nginx -s reload # might fail because the service isn't running yet - -# Change owner, start service -sudo chown -R www-data:www-data ./ -sudo service simplex start + sudo nginx -s reload +fi