Skip to content

Instantly share code, notes, and snippets.

@rileyw
Last active December 14, 2015 23:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rileyw/5165772 to your computer and use it in GitHub Desktop.
Save rileyw/5165772 to your computer and use it in GitHub Desktop.
Percussion CM System Administration Bash Script
#!/bin/bash
# ************************************************
# * Percussion CM System Administration Script *
# ************************************************
check_process() {
[ "$1" = "" ] && return 0
[ `pgrep -n $1` ] && return 1 || return 0
}
code_print() {
echo -e " \e[0;35m$1\e[0m"
}
# Print all in green and the ✔ and $1 in bold
happy_print() {
echo -e " \e[1;32m✔ $1\e[0;32m $2\e[0m"
}
# Print all in red and the ✖ and $1 in bold
sad_print() {
echo -e " \e[1;31m✖ $1\e[0;31m $2\e[0m"
}
# Print extra descriptions for failure
desc_print() {
echo -e " * $1 \e[0;35m$2\e[0m $3"
}
stop_process() {
local home=$1
local bin=$1/bin/RhythmyxDaemon
if [[ -e $bin ]] ; then
desc_print "Stopping process may result in a failure due to system load at the time."
desc_print "Please confirm through log."
$bin stop $home > /dev/null
sleep "15"s
if ! check_process Rhythmyx; then
sad_print "Failed to stop process" "cmSystem"
else
happy_print "Finished stopping process" "cmSystem"
fi
fi
}
start_process() {
local home=$1
local bin=$1/bin/RhythmyxDaemon
if [[ -e $bin ]] ; then
$bin start $home > /dev/null
sleep "5"s
if check_process Rhythmyx; then
sad_print "Failed to start process" "cmSystem"
else
happy_print "Finished starting process" "cmSystem"
desc_print "Starting process may require additional time to launch all dependencies."
desc_print "Please confirm through log."
fi
fi
}
cmSystem() {
if [[ $1 != "" ]] && [[ -e $2 ]]; then
case $1 in
"start"|"Start")
desc_print "Starting" "cmSystem"
desc_print "Locating process"
if ! check_process Rhythmyx; then
sad_print "Process located" "cmSystem" "already started"
else
desc_print "No process located. Starting" "cmSystem"
start_process $2
fi
;;
"stop"|"Stop" )
desc_print "Stopping" "cmSystem"
desc_print "Locating process"
if ! check_process Rhythmyx; then
desc_print "Located process" "cmSystem"
stop_process $2
else
happy_print "No process located. Already stopped" "cmSystem"
fi
;;
"restart"|"Restart" )
desc_print "Restarting" "cmSystem"
desc_print "Locating process"
if ! check_process Rhythmyx ; then
desc_print "Located process"
desc_print "Stopping" "cmSystem"
stop_process $2
if check_progress Rhythmyx; then
desc_print "Starting" "cmSystem"
start_process $2
else
sad_print "Failed to stop process" "cmSystem"
fi
else
desc_print "No process located. Starting" "cmSystem"
start_process $2
fi
;;
"log"|"Log" )
happy_print "Viewing log" ""
;;
* ) sad_print "Invalid argument" "" ;;
esac
else
sad_print "($FUNCNAME) invalid arguments" "{start|restart|stop|log} {path-to-cmSystem}"
fi
}
@rileyw
Copy link
Author

rileyw commented Mar 14, 2013

Log argument is available; however, the code behind the argument is not there. You can see a full write up on this bash script at http://forum.percussion.com/showthread.php?11291-gist-bash-Application-Administration-Bash-Script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment