Skip to content
This repository has been archived by the owner on Nov 9, 2020. It is now read-only.

Produktivsysteme DE

Stefan Haslinger edited this page Feb 20, 2015 · 16 revisions
  • Als Applikations für Mercator empfehlen wir Phusion Passenger
  • Als Web- und Proxyserver für Mercator empfehlen wir Apache oder Nginx
  • sowie als Proxy für Faye und Palava Machine Nginx
  • Mercator kann hinter mehreren Domains betrieben werden, je eine Domain für:
    • CMS-Teil
    • Webshop
    • Podcast
  • Vergessen Sie nicht, die Assets zu kompilieren
    rake assets:precompile RAILS_ENV=production

Delayed Job

  • Produktivsysteme benötigen für des Versenden von E-Mails im Hintergrund die Queuing Engine Delayed Job installiert als Service des Betriebssystems.
  • Legen Sie im Konfigurationsverzeichnis der Applikation eine Datei config/delayed_job.sh an und passen Sie die Variablen an:
#!/bin/bash
logger "Trying to start delayed_job"
date >> /PATH/TO/mercator/log/start_delayed_job.txt
rvm_path=/home/USERNAME/.rvm
source "/home/USERNAME/.rvm/scripts/rvm"

cd /PATH/TO/mercator
/usr/bin/env RAILS_ENV=production /home/USERNAME/.rvm/rubies/ruby-2.1.2/bin/ruby /PATH/TO/mercator/bin/delayed_job restart &>> /var/rails/appname/log/start_delayed_job.txt
logger "delayed_job deamon started"
  • Achten Sie insbesondere auf den Dateiort des Logs (setzen Sie /PATH/TO).
  • Kontrollieren Sie die Ruby Version, Ruby/Rails User und den Pfad der Ruby-Installation. Sie sind je nach verwendetem Ruby Installationsmechanismus unterschiedlich.
  • mit /PATH/TO/mercator/bin/delayed_job start können Sie diesen Prozess manuell in einem Entwicklungssystem starten.

Installation als Service auf einem Produktionssystem

  • Erzeugen Sie ein init Script delayed_job_production im Verzeichnis /etc/init.d und machen Sie es ausführbar (755).
    #!/bin/bash
    # upstart-job for delayed_job
    
    set -e
    APP_PATH="/PATH/TO/mercator"
    
    start_job() {
            echo "Starting delayed job in production"
            sudo -iu webshopadmin bash -c "cd $APP_PATH && RAILS_ENV=production ./bin/delayed_job start"
    }
    
    stop_job() {
            echo "Stopping delayed job in production"
            sudo -iu webshopadmin bash -c "cd $APP_PATH && RAILS_ENV=production ./bin/delayed_job stop"
    }
    
    status_job() {
            echo "Status of production job in staging"
            sudo -iu webshopadmin bash -c "cd $APP_PATH && RAILS_ENV=production ./bin/delayed_job status"
    }
    
    COMMAND="$1"
    shift
    
    case $COMMAND in
    start|stop|status|restart)
        $ECHO
        if [ "$COMMAND" = "stop" ]; then
            stop_job
        elif [ "$COMMAND" = "start" ]; then
            start_job
        elif [ "$COMMAND" = "status" ]; then
            status_job
        elif  [ "$COMMAND" = "restart" ]; then
            stop_job
            sleep 1s
            start_job
            exit 0
        fi
        ;;
    esac

Achtung !

  • Vergessen Sie nicht diesen Prozess bei jedem Auschecken von neuem Code, der im Hintergrund ausgeführt werden soll, neu zu starten.
    sudo service delayed_job_production restart
    Delayed Job läuft sonst mit veraltetem Applikationscode. Nicht nur einmal mussten wir diesen Umstand aus Gedankenlosigkeit auf’s Neue debuggen und lernen.