freehck.script_with_locks

freehck.script_with_locks

This role copies a script that runs any command with a specified lock.

It's very useful for scheduled tasks (crontab jobs). Run it with --help to see the available options.

Role Variables

  • with_locks_script_dir: The directory where the script will be installed. Default is "/opt/scripts".
  • with_locks_script_name: The name of the script. Default is "with-locks".
  • with_locks_install_deps: Whether to install dependencies (moreutils). Default is "yes".

Example Playbook

- hosts:
    - database
  become: yes
  vars:
    lockfile: "/var/lock/db-update-index.lock"
    logfile: "/var/log/db-update-index.log"
  roles:
    - role: freehck.script_with_locks
    - role: freehck.crontask
      crontask_file: "database"
      crontask_name: "update index"
      crontask_minute: "*/30"
      crontask_user: "root"
      crontask_job: "/opt/scripts/with-locks --timestamp --pid --highlight-errors --silent --lock {{ lockfile }} --log {{ logfile }} -- /opt/scripts/perform_update_index.sh"
      # Alternatively, the same command can be written without long options:
      # crontask_job: "/opt/scripts/with-locks -tpes -l {{ lockfile }} -j {{ logfile }} -- /opt/scripts/perform_update_index.sh"

License

MIT

Author Information

Dmitrii Kashin, freehck@freehck.ru

Informazioni sul progetto

create a script that allows to run commands with locks

Installa
ansible-galaxy install freehck.script_with_locks
Licenza
mit
Download
2k
Proprietario