Last active
December 20, 2015 04:18
-
-
Save mechastorm/6069363 to your computer and use it in GitHub Desktop.
Phing task to install Cron Job Config. Must run with sudo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
TargetName: cron:install | |
Partly based on http://codeinthehole.com/writing/deploying-cron-jobs-using-phing/ | |
@param env.name The env name | |
@env.config_path Path in project for the env configs | |
@param project.folder AKA the name of the project | |
--> | |
<target name="cron:install" description="Install Cron Job Config. Run with sudo"> | |
<property name="cron_source_path" value="${env.config_path}/system/cron.d" /> | |
<property name="cron_compiled_path" value="${env.config_path}/build/cron.d" /> | |
<property name="cron_system_path" value="/etc/cron.d/${env.name}-${project.folder}-job" /> | |
<!-- Must run phing task as sudo --> | |
<if> | |
<available file="${cron_system_path}"/> | |
<then> | |
<echo msg="Deleting old cron job ${cron_system_path} " /> | |
<exec command="sudo rm -f ${cron_system_path}" /> | |
</then> | |
</if> | |
<echo msg="Generate cron Config from Properties" /> | |
<if> | |
<available file="${cron_compiled_path}"/> | |
<then> | |
<echo msg="Deleting old build ${cron_compiled_path} " /> | |
<exec command="sudo rm -f ${cron_compiled_path}" /> | |
</then> | |
</if> | |
<copy file="${cron_source_path}" tofile="${cron_compiled_path}" overwrite="true"> | |
<filterchain> | |
<expandproperties /> | |
</filterchain> | |
</copy> | |
<!-- Copy the projects compiled cron job to /etc/cron.d --> | |
<echo msg="Symlink the projects local cron config to ${cron_system_path} " /> | |
<copy file="${cron_compiled_path}" tofile="${cron_system_path}" overwrite="true" /> | |
<exec command="sudo chmod 644 ${cron_system_path}" /> | |
<exec command="sudo chown root:root ${cron_system_path}" /> | |
<!-- Restart cron jobs --> | |
<exec command="sudo /etc/init.d/cron restart" /> | |
</target> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment