Skip to content

Commit

Permalink
add remote_control
Browse files Browse the repository at this point in the history
  • Loading branch information
andylytical committed Feb 26, 2024
1 parent 906f5fa commit 1e09136
Showing 1 changed file with 102 additions and 0 deletions.
102 changes: 102 additions & 0 deletions cleanup/remote_control
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/usr/bin/bash

### VARIABLES
APPDIR=''
HOST=''
ACTION=''
SERVICE=''



### FUNCTIONS
die() {
echo "ERROR $*" >&2
kill 0
exit 99
}


get_host() {
HOST="$1"
[[ -z "$HOST" ]] && die 'Missing host'
}


get_action() {
ACTION="$1"
[[ -z "$ACTION" ]] && die 'Missing action'
}


get_service() {
SERVICE="$1"
case "$SERVICE" in
(jira)
SERVICE=jira
;;
(wiki|confluence)
SERVICE=confluence
;;
esac
}


set_appdir() {
assert_service
case "$HOST" in
jira-test)
APPDIR=/usr/services/jira-standalone
;;
*)
APPDIR="/srv/${SERVICE}/app"
;;
esac
}


assert_service() {
[[ -z "$SERVICE" ]] && die 'Missing service name'
}


mk_cmd() {
case "$ACTION" in
start|stop)
set_appdir
echo "${APPDIR}/bin/${ACTION}-${SERVICE}.sh"
;;
status)
set_appdir
# cmd='test $(ps -efw | grep java | grep jira | wc -l) -eq 1 && echo running || echo stopped'
echo "test \$(ps -efw | grep java | grep ${SERVICE} | grep -v grep | wc -l) -eq 1 && echo running || echo stopped"
;;
logs)
set_appdir
echo "tail ${APPDIR}/logs/catalina.out"
;;
logsf)
set_appdir
echo "tail -f ${APPDIR}/logs/catalina.out"
;;
off|power|shutdown)
echo 'shutdown -h now'
;;
*)
die 'Unknown action'
;;
esac
}


### MAIN

get_host "$1"

get_action "$2"

get_service "$3"

cmd=$( mk_cmd )

set -x
ssh "$HOST" "sudo ${cmd}"

0 comments on commit 1e09136

Please sign in to comment.