How can CRON jobs be created during deployment?

Cron job deployment via install.sh (bash)

  • Why bash? 

    • It is usually available, 

    • easy to understand and 

    • stable

  • process

    • Caveat: definition of Cron in the script or config depending on the environment

    • Decide is what to do according to set environment variables

    • Write the crontab

    • Cleanup temporary files

  • Deployment

    • The bash script is expected by the configuration management system under a specific path and 

    • called parameterized plain or by appointment

    • When it comes to the server by a cron server (ROLES contains "cron") is written a defined crontab

    • This also assumes that the Cron to be run, are actually stored in the specified directory and executable.

Example install.sh (adjustment necessary)

#!/bin/bash if [ -z "$ROLES" ]; then echo 'Roles not set!' exit 1 fi # Main if [ "$ROLES" = "cron" ]; then # write crontab file echo '#Cron by install.sh' > tempfile echo '00 09 * * 1-5 echo hello' >> tempfile echo '00 15 * * * echo bla' >> tempfile # cron example with custom logging echo "* * * * * date >> /var/log/application/cron.log && cd /var/www/ && /usr/bin/php cron.php >> /var/log/application/cron.log 2>&1" >> tempfile # Update crontab crontab tempfile # Clean Up rm tempfile fi echo 'Done successfully.'

Related tutorials

Related components

 

 


root360 Knowledge Base - This portal is hosted by Atlassian (atlassian.com | Privacy Policy)