Translations of this page:
 

Scheduled Tasks (Cronjobs)

For the correct operation of SoSci Survey, the automated regular execution of two scripts is recommended:

  1. Server maintenance (once a day, at night)
  2. Scheduled functions (every minute)

Server Maintenance

Some tasks have to be done regularly on the survey server: archiving old projects, deleting temporary files, deleting obsolete user accounts (dead accounts), and optimizing the database tables.

These tasks are done by a maintenance script /admin/cronjob.php. This script is protected by a password, which you can set in the Server Settings under Configuration. The password is passed to the script as parameter password.

You will find the complete path of the PHP script under Server Settings → Configuration → tab System Settings → Maintenance script.

Manual Maintenance

The server maintenance can also be performed manually, for example on servers that are rarely used.

  • Log in to SoSci Survey as administrator and select Server Management → Server Maintenance → Start cronjob now
  • Alternatively, open the URL directly in the browser: http://www.domain.tld/sosci/admin/cronjob.php?password=SECRET

Return Values

The PHP script returns the following messages:

  • ok – Cronjob done, everything is fine
  • warning – Cronjob done, there were warnings
  • error – Cronjob done, there were errors
  • denied – the password is not correct (if specified)
  • delayed – the cronjob has been run within the last 6 hours and does not need to be run again yet

The server administrator receives an email with further details on the cronjob, which also lists uploaded files, new user accounts, and projects. Some information from the cronjob (e.g., deleted users and projects) is also recorded in the cronjob logfile.

Scheduled Functions

SoSci Survey offers some scheduled functions, e.g., transferring interviews to the database when the server load is low (Write Cache for Interviews), the scheduled dispatch of mailings, or (still in development) regular notifications about the number of survey participants.

For the scheduled functions to work correctly, the script admin/crontask.php has to be run regularly. Calling it every 1-5 minutes is recommended – if you call the script less often, the time at which a task is processed may deviate more from the scheduled time.

You will find the absolute path to the PHP script, which you need for setting up the scheduled execution, under Server Settings → Configuration → tab System Settings → Crontask script.

Setup on Linux

Create two bash scripts, for example in var/www/script/, with the following content. Replace /var/www/html/ with the installation directory of SoSci Survey and PASSWORT with the Password for cronjob set in the Server Settings.

cronjob.sh
#!/bin/bash
cd /var/www/html/admin/
/usr/bin/php /var/www/html/admin/cronjob.php password=PASSWORT
crontask.sh
#!/bin/bash
cd /var/www/html/admin/
/usr/bin/php /var/www/html/admin/crontask.php password=PASSWORT
  • We recommend assigning the scripts to the user www-data. In addition, the scripts need the “executable flag”.
sudo chown www-data cronjob.sh crontask.sh
sudo chmod u+x cronjob.sh crontask.sh
  • The path of php may vary, e.g., /usr/lib/cgi-bin/php. You can determine the correct path, for example, by means of which php.
  • Test calling the script in the console.
sudo -u www-data /s2data/s2survey/script/crontask.sh
  • Then you can create a cronjob by means of sudo crontab -u www-data -e
# m  h   dom mon dow  command
*/1  *    *   *   *   /var/www/script/crontask.sh >/dev/null 2>&1
30   4    *   *   *   /var/www/script/cronjob.sh >/dev/null 2>&1

Setup on Windows

On Windows, the Task Scheduler is responsible for the regular execution of scripts (scheduled tasks, task scheduling).

First, an executable file is required that calls the PHP interpreter and passes the PHP script as a parameter – for example, a simple batch file (*.bat). The paths in the following example have to be adapted to the respective installation.

crontask.bat
C:\php\php.exe C:\webserver\documents\sosci\admin\crontask.php password=PASSWORT
cronjob.bat
C:\php\php.exe C:\webserver\documents\sosci\admin\cronjob.php password=PASSWORT

Run the file as a test to check the paths. The regular execution of this file is then created as a task in the Task Scheduler.

  • Open the Task Scheduler
    • Run dialog
      • Press Windows key + R
      • Enter the command: type taskschd.msc and confirm
    • Alternatively: Control Panel → Administrative Tools → Task Scheduler

In the Task Scheduler

  • In the right pane: Click “Action” (top menu)
  • Select the option: “Create Basic Task…”
  • Follow the wizard: The Create Basic Task Wizard opens
  • Task 1: Run crontask.bat every minute
    • Enter a name (e.g., “SoSci Survey scheduled functions”)
    • Trigger: Select “Daily” → adjust the setting to “Every minute” (or “One time” with a repetition every 1 minute)
    • Action: “Start a program”
    • Program/script: Enter or select the path to crontask.bat
    • Finish
  • Task 2: Run cronjob.bat once a day
    • Enter a name (e.g., “SoSci Survey nightly maintenance”)
    • Trigger: Select “Daily” → set the time (e.g., 00:00)
    • Action: “Start a program”
    • Program/script: Enter or select the path to cronjob.bat
    • Finish
en/server/crontask.txt · Last modified: by 127.0.0.1
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
Driven by DokuWiki