Skip to content

Culturize & Crontab

Douwe De Bock edited this page Sep 22, 2020 · 10 revisions

Automate Culturize with Crontab

Requirements

  • GitHub account
  • Git
  • A GitHub repository containing .htaccess-files (Apache) or redirect.conf-files (Nginx)
  • A Linux server with Apache or Nginx installed

Setup

  1. Clone the git repository to the home folder on the webserver with the following command: git clone -b https:github.com/username/htaccess
  2. Go into your local repository folder with cd ~/$repofolder
  3. Make a connection with the remote (online) repository by typing git fetch --force origin

Option 1: Apache setup

Before you start you will need enable http_proxy mod and restart your webserver by typing following commands in your terminal. (More information)

sudo a2enmod proxy sudo a2enmod proxy_http sudo systemctl restart apache2.service

  1. Create a working tree so that your files on GitHub automatically be placed in the www-folder of your webserver. Type git --work-tree=/var/www/html checkout -f
  2. Create a crontab rule.
    • Open the crontab editor by executing sudo crontab -e in the terminal
    • Next, add the line 0 */1 * * * cd $repofolder/$repofolder.git/ && /usr/bin/git fetch --force origin master:master && /usr/bin/git --work-tree=/var/www/html checkout -f && /usr/bin/git --work-tree=/var/www/html clean -fd to hourly pull the GitHub repository where your PIDs are stored. This will pull possible changes every hour from the remote repository and put the files in /var/www/.
    • Git fetch will get the changes from the server, git checkout will apply the changes to the .htaccess files. git clean is optional, we use it to remove the unchecked changes

Option 2: Nginx setup

  1. Create a working tree so that your files on GitHub automatically be placed in the folder of your choosing. In this case the folder needs to be in /etc/nginx. Type the following command git --work-tree=/etc/nginx/culturize/ checkout -f.

  2. We need to add this location to the exsisting nginx configuration. Open the configuration of the website you want the redirect to happen from /etc/nginx/sites-enabled/domain.conf and add this line to in server block include /etc/nginx/culturize/nginx_redirect.conf;. If a sub directory was selected in CultURIze during the nginx configuration generation this should also be configured here e.g. include /etc/nginx/culturize/<subdir>/nginx_redirect.conf;

    server {
        listen 80;
        
        server_name example.com;
        
        root /var/www/example.com;
        index index.html;
        
        include /etc/nginx/culturize/nginx_redirect.conf;
        
        location / {
            try_files $uri $uri/ =404;
        }
    }
    
  3. Create a crontab rule.

    • open the crontab editor executing sudo crontab -e in the terminal.
    • next, add the line t 0 */1 * * * cd $repofolder/$repofolder.git/ && /usr/bin/git fetch --force origin master:master && /usr/bin/git --work-tree=/etc/nginx/culturize checkout -f && /usr/bin/git --work-tree=/etc/nginx/culturize clean -fd && nginx -s reload in the file in the terminal to hourly pull the GitHub repository where your PIDs are stored. This will pull possible changes every hour from the remote repository and put the files in /etc/nginx/culturize/.
      • git fetch will download the changes from the server.
      • git checkout -f This is used to throw away local changes.
      • git clean is optional, we use it to remove the unchecked changes. ([more informatoin]https://git-scm.com/docs/git-clean)
      • && nginx -s reload will reload the nginx webserver, without interrupting already running services. This is to load in the new configuration files.