Skip to content

Instantly share code, notes, and snippets.

@SemVerTsar
Last active August 30, 2016 10:57
Show Gist options
  • Save SemVerTsar/40ee56294d7537eebd3112af88541af4 to your computer and use it in GitHub Desktop.
Save SemVerTsar/40ee56294d7537eebd3112af88541af4 to your computer and use it in GitHub Desktop.

Step 1: Provision a server

  • Completed

Step 2: Setup DNS

Using the IP address from the server

  • Completed

Step 3: Setup OS level tools

You will need the Incuna scripts repo

  • From the Incuna scripts repo

     fab -f setup_salt.py deploy:your-new-site.com
    • Completed
  • From the salt server

    • Check the new server is available.

       sudo salt-key -L
      • Completed
    • Accept the new server.

       sudo salt-key -a your-new-site.com
      • Completed
    • Push high state to the new server.

       sudo salt your-new-site.com state.highstate -v
      • Completed

Step 4: Add server to Distelli

On the new server

  • Download the Distelli agent.

     curl -sSL https://www.distelli.com/download/client | sh
    • Completed
  • Install the Distelli agent.

     sudo /usr/local/bin/distelli agent install
    • Completed

The Distelli setup instructions for setting up Applications & builds are located here.

Step 5: Setup the site folders

On the new server

  • Navigate to the www folder and create a folder for the new site.

     cd /var/www/
     mkdir your-new-site.com
     cd /var/www/your-new-site.com
    • Completed
  • Create the Client & Static media folders.

     mkdir client_media static_media
    • Completed
  • Grant the correct permissions.

     sudo chgrp -R www-data .

    This will change the group permission of /var/www/your-new-site.com, /var/www/your-new-site.com/client_media & /var/www/your-new-site.com/static_media.

     sudo chown distelli static_media
     sudo chown distelli client_media
    • Completed

Step 6: Setup the environment variables

  • Create a folder for the envitonment variables.

     cd /var
     mkdir conf
     cd conf
     mkdir env
     cd env
    • Completed
  • Change the permissions for /var/conf/env.

     sudo chown -R incuna .
    • Completed
  • Create the environment variables.

    The environment variables will change depending on the project. These are the core variables more most projects.

    Name Value
    ALLOWED_HOSTS you-new-site.com
    DATABASE_URL postgres://user:[email protected]/database_name
    MEDIA_ROOT /var/www/your-new-site.com/client_media
    MEDIA_URL https://your-new-site.com/client/
    OPBEAT_APP_ID app_id
    OPBEAT_ORGANIZATION_ID org_id
    OPBEAT_SECRET_TOKEN token
    SECRET_KEY secret_key
    STATIC_ROOT /var/www/your-new-site.com/static_media
    STATIC_URL https://your-new-site.com/static/
    • To create the variable l, where Name and Value are the column labels above:

       echo 'Value' > Name
    • Completed

Step 7: Setup the Database

  • Start a PSQL shell as the postgres user.

     sudo -u postgres psql
    • Completed

Inside the psql shell.

  • Create the database.

     create database new_site_db;
    • Completed
  • Create the user with a password.

     create user new_user with password 'new_password';
    • Completed
  • Grant permissions to the user on the database.

     grant all on databse new_site_db to new_user;
    • Completed

These credentials must match the DATABASE_URL environment variable.

Step 8: Setup Supervisor

  • Create the Supervisor config.

     sudo vim /etc/supervisor/conf.d/your_new_site.conf
    • Completed
  • Reload & restart Supervisor.

     sudo supervisorctl

    This will open a supervisor shell.

     reload

    This will reload the all supervisor config files.

     restart your_new_site

    This will restart the your_new_site process, you could also user restart all to restart all processes.

    Ctrl d to exit the Supervisor shell.

    • Completed

    ###Supervisor help

    You do not need to enter a shell to use supervisor. sudo supervisorctl restart all

    Use tail -f process_name within a supervisor shell to help resolve errors.

Step 9: Setup Nginx

  • Create the Nginx config.

     vim /etc/nginx/sites-available/your_new_site.conf
     ln -s /etc/nginx/sites-available/your_new_site.conf /etc/nginx/sites-enabled/your_new_site.conf

    Test the config file is valid using sudo /etc/init.d/nginx configtest.

    • Completed
  • Reload and restart Nginx.

     sudo /etc/init.d/nginx reload

    Reloads the nginx config.

     sudo /etc/init.d/nginx restart

    Restarts the nginx config.

    • Completed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment