Skip to content

Instantly share code, notes, and snippets.

@jalaziz
Last active December 23, 2015 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jalaziz/6684180 to your computer and use it in GitHub Desktop.
Save jalaziz/6684180 to your computer and use it in GitHub Desktop.
Localshop upstart and nginx configs -- WIP

Setup

  1. Create a new user on the system:

    adduser --system --group --shell /bin/sh --home /opt/localshop localshop
  2. Clone localshop into /opt/localshop. (as of writing this README, localshop is outdated on pypi)

  3. Create the virualenv and install the required packages:

    cd /opt/localshop
    virtualenv .venv
    source .venv/bin/activate
    pip install --pre -r requirements.txt
  4. Place the upstart configs in /etc/init.

  5. Initialize localshop:

    cd /opt/localshop
    source .venv/bin/activate
    export LOCALSHOP_HOME=/opt/localshop
    python manage.py init
description "Localshop Celery"
start on started localshop
stop on stopping localshop
respawn limit 10 5
chdir /opt/localshop
setuid localshop
env VIRTUAL_ENV=/opt/localshop/.venv
env PYTHONUNBUFFERED=True
env LOCALSHOP_HOME=/opt/localshop
exec $VIRTUAL_ENV/bin/localshop celery worker --no-execv -B -E --loglevel=info >> /var/log/localshop/celery.log 2>&1
description "Localshop Web"
start on started localshop
stop on stopping localshop
respawn limit 10 5
chdir /opt/localshop
setuid localshop
env VIRTUAL_ENV=/opt/localshop/.venv
env PYTHONUNBUFFERED=True
env LOCALSHOP_HOME=/opt/localshop
exec $VIRTUAL_ENV/bin/gunicorn localshop.wsgi:application -R -b localhost:8000 -w 2 -k gevent --error-logfile ->> /var/log/localshop/web.log 2>&1
description "Localshop"
pre-start script
mkdir -p /var/log/localshop
chown -R localshop /var/log/localshop
end script
start on runlevel [2345]
stop on runlevel [016]
server {
listen 80;
server_name pypi.jalaziz.io;
location / {
rewrite ^ https://$server_name$request_uri permanent;
}
}
server {
listen 443 ssl;
server_name pypi.jalaziz.io;
charset utf-8;
access_log /var/log/nginx/localshop.access.log;
error_log /var/log/nginx/localshop.error.log;
location /assets/ {
alias /opt/localshop/assets/;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://localhost:8000;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment