About Asher256

GitHub: http://github.com/Asher256

Puppet module to configure LizardFS (Distributed File System) on Linux

I recently developed the Puppet module puppet-lizardfs you can use to configure LizardFS (a highly-available distributed file system / DFS). LizardFS makes files secure by keeping all data in many replicas spread over several Linux servers.

The Puppet module puppet-lizardfs is an open source project, and community contributions are essential for keeping it great. I encourage you to contribute. Send me your pull requests on Github! Currently, puppet-lizardfs supports the operating systems Debian/Ubuntu and RedHat/CentOS.

A Puppet example: Continue reading

3 advices to write robust Bash scripts

To write robust Bash scripts, I recommend you to:

1. Activate the Bash options: errexit, nounset

Add these two options at the top of your Bash scripts:

  • errexit will stop your Bash script each time a command in your script returns an exit code different from “0”. It does not show any message when it quits, this is why it is important to show a traceback (check the second advice below “show a Bash traceback”).
  • nounset will stop your script and output an error if you attempt to use undefined variables. nounset is very important because it can avoid you to run dangerous commands like: rm –fr “/$undefinedvariable”

2. Show a Bash traceback

Because the option “errexit” does not show any message when it stops your Bash script in some cases (for example var=$(yourcommand) will exit without any message, even when yourcommand returns an exit code different from zero), I recommend you to add the code below to show a traceback each time “errexit” forces your Bash script to stop:

The traceback will help you to know which command in your Bash script failed with a return code different from “0”:

3. Check your Bash scripts with shellcheck and follow the recommendations of Advanced Bash-Scripting Guide.

Temporarily prevent Linux from shutting down

Accidental shutdown or reboot is a serious blunder, especially if the kernel is being updated in the background.

I recommend you to use systemd-inhibit to prevent Linux from shutting down while your important cron jobs are running (e.g. operating system update scripts):

systemd-inhibit will block the shutdown or reboot until the update script is finished.

Additional options:

  • –who=”your name”
    A human-readable name
  • list
    List all active inhibition locks

How to stop and remove all docker images and containers

Docker is a great tool, but it can sometimes consume a lot of disk space. docker-clean is a simple bash script you can use to remove all docker images and containers with one command:

To stop and remove all Docker containers:

To remove all Docker images: