From: Guillaume Pellerin Date: Mon, 5 Dec 2016 00:45:10 +0000 (+0100) Subject: Fix many pathsi and args, fix doc X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=5b93ec812b2ea20ca425788eda3d3ff188312787;p=mezzo.git Fix many pathsi and args, fix doc --- diff --git a/app/bin/app.sh b/app/bin/app.sh new file mode 100755 index 00000000..38b695ba --- /dev/null +++ b/app/bin/app.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +# paths +app='/srv/app' +manage=$app'/manage.py' +wsgi=$app'/wsgi.py' +static='/srv/static/' +media='/srv/media/' +src='/srv/src/' +log='/var/log/uwsgi/app.log' + +# uwsgi params +port=8000 +processes=8 +threads=16 +autoreload=3 +uid='www-data' +gid='www-data' +# patterns='*.js;*.css;*.jpg;*.jpeg;*.gif;*.png;*.svg;*.ttf;*.eot;*.woff;*.woff2' + +# Staging +# pip install xlrd +# pip install -U https://forge.ircam.fr/p/django-eve/source/download/dev/ +# pip install https://forge.ircam.fr/p/django-prestashop/source/download/master/ --src /srv/lib +# pip install -U https://github.com/stephenmcd/grappelli-safe/archive/dynamic_stacked.zip +pip install django-querysetsequence==0.6.1 django==1.9.11 +#pip install django-autocomplete-light django-querysetsequence +#/usr/bin/yes | pip uninstall django-orderable + +chown -R $uid:$gid $media + +# waiting for other services +sh $app/bin/wait.sh + +# django setup +python $manage wait-for-db +# python $manage migrate --noinput +# python $manage bower_install -- --allow-root +python $manage create-admin-user +# @todo searching every fixtures file in each folder +python $manage loaddata $app/organization/job/fixtures/organization-job.json +python $manage loaddata $app/organization/projects/fixtures/organization-projects-repositorysystems.json + +# app start +if [ "$1" = "--runserver" ]; then + python $manage runserver 0.0.0.0:8000 +else + # static files auto update + # watchmedo shell-command --patterns="$patterns" --recursive \ + # --command='python '$manage' collectstatic --noinput' $app & + + python $manage collectstatic --noinput + + uwsgi --socket :$port --wsgi-file $wsgi --chdir $app --master \ + --processes $processes --threads $threads \ + --uid $uid --gid $gid --logto $log \ + --py-autoreload $autoreload +fi diff --git a/app/bin/wait.sh b/app/bin/wait.sh new file mode 100755 index 00000000..202c4d13 --- /dev/null +++ b/app/bin/wait.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +set -e + +host=$(env | grep _TCP_ADDR | cut -d = -f 2) +port=$(env | grep _TCP_PORT | cut -d = -f 2) + +echo -n "waiting for TCP connection to $host:$port..." + +while ! nc -w 1 $host $port 2>/dev/null +do + echo -n . + sleep 1 +done + +echo 'ok' diff --git a/app/manage.py b/app/manage.py old mode 100644 new mode 100755 diff --git a/app/scripts/app.sh b/app/scripts/app.sh deleted file mode 100644 index 7c27d30c..00000000 --- a/app/scripts/app.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/bash - -# paths -app='/srv/app' -manage=$app'/manage.py' -wsgi=$app'/wsgi.py' -static='/srv/static/' -media='/srv/media/' -src='/srv/src/' - -# uwsgi params -port=8000 -processes=8 -threads=16 -autoreload=3 -uid='www-data' -gid='www-data' -patterns='*.js;*.css;*.jpg;*.jpeg;*.gif;*.png;*.svg;*.ttf;*.eot;*.woff;*.woff2' -log='/var/log/uwsgi/app.log' - -# Staging -# pip install xlrd -# pip install -U https://forge.ircam.fr/p/django-eve/source/download/dev/ -# pip install https://forge.ircam.fr/p/django-prestashop/source/download/master/ --src /srv/lib -# pip install -U https://github.com/stephenmcd/grappelli-safe/archive/dynamic_stacked.zip -pip install django-querysetsequence==0.6.1 django==1.9.11 -#pip install django-autocomplete-light django-querysetsequence -#/usr/bin/yes | pip uninstall django-orderable - -chown -R $uid:$gid $media - -# waiting for other services -sh $app/scripts/wait.sh - -# django setup -python $manage wait-for-db -# python $manage migrate --noinput -# python $manage bower_install -- --allow-root -python $manage create-admin-user -# @todo searching every fixtures file in each folder -python $manage loaddata $app/organization/job/fixtures/organization-job.json -python $manage loaddata $app/organization/projects/fixtures/organization-projects-repositorysystems.json - -# app start -if [ "$1" = "--runserver" ]; then - python $manage runserver 0.0.0.0:8000 -else - # static files auto update - # watchmedo shell-command --patterns="$patterns" --recursive \ - # --command='python '$manage' collectstatic --noinput' $app & - - python $manage collectstatic --noinput - - uwsgi --socket :$port --wsgi-file $wsgi --chdir $app --master \ - --processes $processes --threads $threads \ - --uid $uid --gid $gid --logto $log \ - --py-autoreload $autoreload -fi diff --git a/app/scripts/wait.sh b/app/scripts/wait.sh deleted file mode 100644 index 202c4d13..00000000 --- a/app/scripts/wait.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh - -set -e - -host=$(env | grep _TCP_ADDR | cut -d = -f 2) -port=$(env | grep _TCP_PORT | cut -d = -f 2) - -echo -n "waiting for TCP connection to $host:$port..." - -while ! nc -w 1 $host $port 2>/dev/null -do - echo -n . - sleep 1 -done - -echo 'ok' diff --git a/bin/pull.sh b/bin/pull.sh index 69c38832..f8e118e5 100755 --- a/bin/pull.sh +++ b/bin/pull.sh @@ -4,5 +4,5 @@ sudo chown -R $USER var/media sudo chown -R $USER var/backup git pull git submodule foreach git pull -docker-compose run db /srv/scripts/restore_db.sh +docker-compose run db /srv/bin/restore_db.sh gulp build diff --git a/bin/push.sh b/bin/push.sh index 872d2eba..710b0fdd 100755 --- a/bin/push.sh +++ b/bin/push.sh @@ -2,7 +2,7 @@ echo "----------------------------" echo `date +\%Y\%m\%d-\%H-\%M-\%S` -docker-compose run db /srv/scripts/backup_db.sh +docker-compose run db /srv/bin/backup_db.sh cd var git add . git commit -a -m "update DB and media" diff --git a/doc/src/install.rst b/doc/src/install.rst index 18906ccb..a7088c2e 100644 --- a/doc/src/install.rst +++ b/doc/src/install.rst @@ -64,24 +64,18 @@ Then browse the app at http://localhost:8020/ On MacOS or Windows, we need to replace 'localhost' by the IP given by the docker terminal. -Install as a daemon -+++++++++++++++++++++ - -Run daemon install script:: - - sudo ./install.py - -Run daemon and install cron:: +Daemonize ++++++++++++ - sudo ./install.py --user=$USER --cron +The install the entire composition so that it will be automatically run at boot and in the background:: - You can find logs at /var/log/mezzanine-organization + sudo bin/install.py options:: --uninstall : uninstall the daemon --cron : install cron backup rule (every 6 hours) - --user : specify user + --user : specify user for cron rule --systemd : use systemd --composition_file : the path of the YAML composition file to use (optional) diff --git a/doc/src/maintenance.rst b/doc/src/maintenance.rst index 4e90e257..9c7b038a 100644 --- a/doc/src/maintenance.rst +++ b/doc/src/maintenance.rst @@ -22,13 +22,11 @@ Upgrade application, all dependencies, data from master branch and also recompil Backup & restore DB ++++++++++++++++++++ -To backup the database, in **another** terminal (or a Docker Quickstart Terminal):: +To backup the database and push it to the var (data) own repository (**only** prod!):: - bin/push.sh #(only prod !) + bin/push.sh -giving your user password if asked... - -To restore the backuped database, in another terminal (or a Docker Quickstart Terminal):: +To restore the backuped database and rebuild front:: bin/pull.sh diff --git a/docker-compose.yml b/docker-compose.yml index 5aeb4d4d..e081a594 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -23,9 +23,13 @@ var: volumes: - ./var/media:/srv/media - ./var/backup:/srv/backup - - /srv/static - - /srv/bower + - ./var/log/uwsgi:/var/log/uwsgi + - ./var/log/nginx:/var/log/nginx + - ./var/log/app:/var/log/app + - ./bin:/srv/bin - ./doc:/srv/doc + - /srv/bower + - /srv/static command: "true" db: @@ -33,24 +37,21 @@ db: volumes_from: - var volumes: - - ./scripts:/srv/scripts - ./var/lib/postgresql/data:/var/lib/postgresql/data environment: - POSTGRES_PASSWORD=hyRob0otlaz4 app: build: . - command: /bin/bash scripts/app.sh + command: /bin/bash bin/app.sh volumes: - ./app:/srv/app - - ./var/log/uwsgi:/var/log/uwsgi - ./lib/grappelli-safe:/srv/lib/grappelli-safe - ./lib/mezzanine-agenda:/srv/lib/mezzanine-agenda - ./lib/django-eve:/srv/lib/django-eve - ./lib/django-prestashop:/srv/lib/django-prestashop # - ./lib/mezzanine/:/srv/lib/mezzanine # - ./lib/cartridge/:/srv/lib/cartridge - - ./doc:/srv/doc volumes_from: - var expose: @@ -66,7 +67,6 @@ nginx: - "8020:80" volumes: - ./etc/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf - - ./var/log/nginx/:/var/log/nginx volumes_from: - var links: diff --git a/env/dev.yml b/env/dev.yml index 2293a025..4eedc10c 100644 --- a/env/dev.yml +++ b/env/dev.yml @@ -20,7 +20,7 @@ app: - command: /bin/sh scripts/app.sh --runserver + command: /bin/sh bin/app.sh --runserver volumes: - ./app/:/srv/app ports: diff --git a/env/eve.yml b/env/eve.yml index 3bce54cc..dffbc255 100644 --- a/env/eve.yml +++ b/env/eve.yml @@ -22,15 +22,14 @@ evedb: image: postgres:9.5 volumes_from: - - data + - var volumes: - - ./scripts/:/srv/scripts - ./data/external/eve/postgresql/data/:/var/lib/postgresql/data environment: - POSTGRES_USER=eve - POSTGRES_DB=eve - POSTGRES_PASSWORD=q2nqzt0WGnwWé,256 - + app: links: - db diff --git a/env/prestashop.yml b/env/prestashop.yml index d371047d..b64717cf 100644 --- a/env/prestashop.yml +++ b/env/prestashop.yml @@ -22,9 +22,8 @@ prestadb: image: mariadb volumes_from: - - data + - var volumes: - - ./scripts/:/srv/scripts - ./data/external/prestashop/mysql/:/var/lib/mysql environment: - MYSQL_ROOT_PASSWORD=mysecretpassword diff --git a/etc/nginx/conf.d/default.conf b/etc/nginx/conf.d/default.conf index 1b1a9283..9fca538b 100644 --- a/etc/nginx/conf.d/default.conf +++ b/etc/nginx/conf.d/default.conf @@ -22,7 +22,7 @@ server { # Django static location /doc { - alias /srv/doc; # your Django project's static files - amend as required + alias /srv/doc/build/html; # your Django project's static files - amend as required } location / {