Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents
maxLevel1

asg-protection

description

For scripts with a long runtime, it may happen that the execution server is deleted during execution by our automatic scaling. This script activates or deactivates a protection mechanism for the executing server that prevents this deletion Code. If this is not equal to 0 (number zero), an error occurred and the protection was not activated / deactivated. Possible reasons are:

  • The server is currently down

  • The hardware of the server is currently being modified (enlarged, reduced, restarted, etc.)

  • The script was called too often in a short period of time (> about 1000 views per second)

usage

Enable protection:

Code Block
languagebash
if asg-protection on; then
   # Commands if protection could not be activated
   # Ex: exit
fi


Disable protection:

Code Block
languagebash
if asg-protection off; then
   # Commands if protection could not be disabled
   # Ex: exit
fi

Get current state:

Code Block
languagebash
asg-protection get
  • return code is 0, when ASG protection is enabled

  • return code is 1, when ASG protection is disabled

  • return code is 5, when the server is a single server

check-log-registration  

description

There are cases where the application can not be customized so the log is registered by the application. In these cases, this script can be used. It recursively finds all files in a given path and registers them if they have not been registered yet. It is optimized for use as cronjob. The script has to be run as www-data, which will be done automatically by using the command in the install.sh. If you want to test the script manually you have to add the prefix 'sudo -u www-data'

usage

Log log files in a path:

Code Block
languagebash
check-log-registration /full/path/to/log-folder/ [role1 [role2 [roleN]]]

...

Code Block
languagebash
check-log-registration /full/path/to/log-folder/ web backend

get-application-env

description

 If the server is used to host an application, the script returns all environment parameters (eg database access credentials, memcache URL, etc.). It supports output in text and json format.

Note

You need to run this script directly on the application instance. The script will not return environment parameters on a natgw because no application runs on a natgw.

This command is not usable on our docker setups.

usage

Return environment parameters for all server roles:

...

Code Block
languagebash
$ get-application-env -h

get-instances-by-role

description

This script returns a list of all servers in a project that belong to a role. It supports output in text and json format.

usage

Return all servers with the same role, such as:

...

Code Block
languagebash
get-instances-by-role --project project role
# e.g.
get-instances-by-role --project proj2 web

hook-memcache-flush.sh

description

This script can be used as a deploy hook to delete all data from a memcache cluster after a project deployment. It automatically detects all existing memcache clusters. If only one cluster exists, this is deleted. If more clusters exist, the cluster to be cleared is queried via a selection.

usage

Delete based on automatic determination:

...

Code Block
languagebash
hook-memcache-flush.sh -u cluster-url
# Beispiel
hook-memcache-flush.sh -u test-r3-45git3.00y7nk.cfg.euc1.cache.amazonaws.com:11211

register-log

description

Upon request, we provide a logging system that collects log files to a central log server and stores them for analysis for a defined period of time. This script can be used to log log files dynamically. This is necessary, for example, for log files with a dynamic path (eg date or partner ID).

Currently up to 6600 log files can be registered.

usage

register logs:

Code Block
languagebash
register-log -h
/usr/local/bin/register-log [-h] [-k] [path_to_log] [role]

-h        : show this help
-k        : prevents our cleanup routines to remove the configuration for the logfile when the log file does not exist
[role]    : for instances with multiple roles, please use this option and define a role

...

(warning) The script register-log checks if a log file exists to avoid unnecessary configs. This results in the use of register-log during installation, e.g. via install.sh may cause problems, as the paths are not yet fully established. We therefore recommend making a touch on the log file and creating the file.

usage at install.sh
Code Block
languagebash
register-log -k /full/path/to/logfile [role] # you should incorporate pwd

run-once-per-role.sh

description

This script is intended to run on all servers with the same role (e.g. Auto-Scaling Group) and ensure that the given command is only run once.

This is done by collecting all server with the given role, sorting them by their IP address and only run CMD when the local IP address matches the first address in the generated list.

usage

The first argument of the script has to be the role name that is deployed.

...

Be aware of the escaping of special characters in Bash (&;|$ and so on) necessary if they are part of the command to run.

Use-Case install.sh

Using run-once-per-role.sh you can run a command via install.sh that should only run once per deployment, e.g. flush caches.

This example code in the install.sh run the clear-cache function of 'artisan':

install.sh
Code Block
languagebash
#!/bin/bash

[...]

run-once-per-role.sh "${ROLE}" /var/www/web/public/bin/artisan cache:clear

[...]

Use-Case Cronjob

With run-once-per-role.sh you can install a cronjob that should run only once on all systems and it still will be running on only one system.

...

Code Block
* * * * * /usr/local/bin/run-once-per-role.sh 'web' /var/www/web/public/bin/artisan cron:start

varnish-flush.sh

description

This script deletes data from a Varnish cache.

usage

Script using the URL to be deleted on the Jump server.

...