Last active
February 17, 2021 17:29
-
-
Save emmanuelnk/8903cb771288cc92d11101a1f9db70a1 to your computer and use it in GitHub Desktop.
The NewBoston Bank and Validator Setup Scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description = Service to run Django API | |
After = network.target | |
[Service] | |
EnvironmentFile = /etc/bank/environment | |
User = deploy | |
ExecStart = /usr/local/bin/start_api.sh | |
[Install] | |
WantedBy = multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CELERYD_NODES="w1" | |
CELERY_BIN="/usr/local/bin/celery" | |
CELERY_APP="config.settings" | |
CELERYD_MULTI="multi" | |
CELERYD_OPTS="--time-limit=1800 --concurrency=2" | |
CELERYD_PID_FILE="/var/log/celery/%n.pid" | |
CELERYD_LOG_FILE="/var/log/celery/%n%I.log" | |
CELERYD_LOG_LEVEL="DEBUG" | |
DJANGO_APPLICATION_ENVIRONMENT=production | |
NETWORK_SIGNING_KEY=YOUR_NID_SIGNING_KEY | |
SECRET_KEY=YOUR_SECRET_KEY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Bank Celery Service | |
After=network.target | |
[Service] | |
Type=forking | |
User=deploy | |
EnvironmentFile=/etc/bank/celery.conf | |
WorkingDirectory=/var/www/Bank | |
ExecStart=/bin/sh -c '${CELERY_BIN} multi start ${CELERYD_NODES} \ | |
-A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} \ | |
--logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}' | |
ExecStop=/bin/sh -c '${CELERY_BIN} multi stopwait ${CELERYD_NODES} \ | |
--pidfile=${CELERYD_PID_FILE}' | |
ExecReload=/bin/sh -c '${CELERY_BIN} multi restart ${CELERYD_NODES} \ | |
-A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} \ | |
--logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}' | |
[Install] | |
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from os.path import expanduser | |
from django.core.management.utils import get_random_secret_key | |
from nacl.encoding import HexEncoder | |
from thenewboston.accounts.manage import create_account | |
from pathlib import Path | |
""" | |
Running this script will produce all keys necessary for deploying a new node. | |
Account Number Signing Key: | |
2ea2542cb0b1176bd773beb58051c8baba832df30fe1f853e62ec9628032e087 | |
Account Number: | |
a007f798fe362a3fc891f48dcee52fb8278f65821c55275d726a8e4f53a96536 | |
NID Signing Key: | |
642df386806978baf63d660773983d13f19a714615c8acab74a0e16b775ca6c8 | |
NID: | |
4a1331c318325ee601757aa4be45b34260fedf2f42071a871e16479b6cfd4746 | |
SECRET_KEY: | |
okjd6yv)7wt#+ir#v2-j$9w!brgw3(k1#a28is5i7puk59itptm | |
""" | |
def write_to_file(keys_dict, key_file): | |
# write keys to tnb_keys file | |
# set ENV variables by running: source ~/tnb/tnb_keys | |
with open(key_file, 'a') as output_file: | |
for key, value in keys_dict.items() : | |
output_file.write('export {}="{}"\n'.format(key, value)) | |
output_file.close() | |
def display_key_pair(*, label, key_file): | |
""" | |
Create and display key pair information | |
""" | |
private_key, public_key = create_account() | |
private_key = private_key.encode(encoder=HexEncoder).decode('utf-8') | |
public_key = public_key.encode(encoder=HexEncoder).decode('utf-8') | |
print(f'\n{label}_SIGNING_KEY:\n{private_key}') | |
print(f'\n{label}:\n{public_key}') | |
keys_dict = {} | |
keys_dict[f'{label}_SIGNING_KEY'] = private_key | |
keys_dict[f'{label}'] = public_key | |
write_to_file(keys_dict, key_file) | |
def run(): | |
""" | |
Generate node keys | |
""" | |
home_path = expanduser("~") | |
key_file = Path(f"{home_path}/tnb/tnb_keys") | |
# if file already exists, do nothing | |
if key_file.is_file(): | |
return | |
display_key_pair(label='ACCOUNT_NO', key_file=key_file) | |
display_key_pair(label='NID', key_file=key_file) | |
random_secret_key = get_random_secret_key() | |
print(f'\nSECRET_KEY:\n{random_secret_key}') | |
write_to_file({ 'SECRET_KEY': random_secret_key }, key_file) | |
if __name__ == '__main__': | |
run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
upstream django { | |
server 127.0.0.1:8001; | |
} | |
server { | |
listen 80 default_server; | |
server_name localhost; | |
charset utf-8; | |
client_max_body_size 75M; | |
location /media { | |
alias /var/www/Bank/media; | |
} | |
location /static { | |
alias /var/www/Bank/static; | |
} | |
# Send all non-media requests to the Django server | |
location / { | |
proxy_pass http://django; | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection "upgrade"; | |
proxy_redirect off; | |
proxy_set_header Host $host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header X-Forwarded-Host $server_name; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
cd /var/www/Bank | |
daphne -p 8001 config.asgi:application |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment