-
-
Save santosh-gouda/3c8ee141443ed30955d3fe37d2c6b7db to your computer and use it in GitHub Desktop.
[Bash main script] #bash
This file contains hidden or 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
| #!/bin/bash | |
| set -o errexit | |
| set -o pipefail | |
| set -o nounset | |
| # --- Helper scripts begin --- | |
| #/ Usage: saltstackcmd <command> [options...] | |
| #/ | |
| #/ Commands: | |
| #/ | |
| #/ start Start the salt master. | |
| #/ stop Stop the salt master. | |
| #/ | |
| #/ Options: | |
| #/ -h, --help Show this help message and exit. | |
| #/ -v, --verbose Turn on command verbosity. | |
| #/ | |
| Usage() { grep '^#/' "$0" | cut -c4- ; exit 0 ; } | |
| #__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
| #__file="${__dir}/$(basename "${BASH_SOURCE[0]}")" | |
| #__base="$(basename "${__file}" .sh)" | |
| #__root="$(cd "$(dirname "${__dir}")" && pwd)" # <-- change this as it depends on your app | |
| readonly LOG_FILE="/tmp/$(basename "$0").log" | |
| readonly DATE_FORMAT="+%Y-%m-%d %H:%M:%S.%3N" | |
| info() { ( echo $(date "${DATE_FORMAT}") [INFO] $* | tee -a "$LOG_FILE" >&2 ; ) } | |
| warning() { ( echo $(date "${DATE_FORMAT}") [WARNING] $* | tee -a "$LOG_FILE" >&2 ; ) } | |
| error() { ( echo $(date "${DATE_FORMAT}") [ERROR] $* | tee -a "$LOG_FILE" >&2 ; ) } | |
| fatal() { echo $(date "${DATE_FORMAT}") [FATAL] $* | tee -a "$LOG_FILE" >&2 ; kill 0 ; } | |
| cleanup() { | |
| local result=$? | |
| if (( result > 0 )); then | |
| error "Exiting with code ${result}." | |
| else | |
| info "Exiting with code ${result}." | |
| fi | |
| } | |
| trap cleanup EXIT | |
| trap "kill 0" SIGINT | |
| if [ $# -lt 1 ]; then | |
| Usage | |
| exit | |
| fi | |
| function cmd_start(){ | |
| echo 'cmd_start()' | |
| } | |
| function main() { | |
| local cmd=$1 | |
| shift | |
| if [ "$cmd" == "start" ]; then | |
| cmd_start "$@" | |
| else | |
| Usage | |
| fi | |
| return | |
| } | |
| if [[ "${BASH_SOURCE[0]}" = "$0" ]]; then | |
| main "$@" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment