This repository has been archived by the owner on Aug 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better service management scripts (#532)
* Scripts to manage hillview services
- Loading branch information
Mihai Budiu
authored
Aug 21, 2019
1 parent
2f6b673
commit 2f570d8
Showing
20 changed files
with
358 additions
and
132 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/sh | ||
# Runs another process in a loop | ||
|
||
if [ $# -le 1 ]; then | ||
echo "Usage: forever.sh pidfile command" | ||
echo "Re-runs command every time it terminates" | ||
echo "Writes its own pid in pidfile" | ||
exit 1 | ||
fi | ||
|
||
pidfile=$1 | ||
shift | ||
|
||
echo "Running $1 forever" | ||
echo $$ >${pidfile} | ||
while /bin/true; do | ||
$* | ||
sleep 2 | ||
echo "Restarting..." | ||
done |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/bin/bash | ||
# This is teamplate for a script that manages a hillview aggregator as a Unix service. | ||
|
||
#REPLACE_WITH_VARIABLES | ||
|
||
FOREVERPID="forever-aggregator.pid" | ||
PIDFILE="hillview-aggregator.pid" | ||
|
||
cd ${SERVICE_DIRECTORY} | ||
|
||
start() { | ||
if [ "x${CLEANUP}" == "x1" ]; then | ||
rm -f hillview-agg.log hillview-agg.log.* hillview-agg.log*.lck | ||
fi | ||
./forever.sh ${FOREVERPID} nohup java -ea -Dlog4j.configurationFile=./log4j.properties -server -Xmx${HEAPSIZE} -jar ${SERVICE_DIRECTORY}/hillview-server-jar-with-dependencies.jar ${SERVICE_DIRECTORY}/workers 0.0.0.0:${AGGREGATOR_PORT} >nohup.out 2>&1 & | ||
} | ||
|
||
killbypid() { | ||
local PIDFILE=$1 | ||
if [ -f ${PIDFILE} ]; then | ||
# First try to find the service pid | ||
read LINE < ${SERVICE_DIRECTORY}/${PIDFILE} | ||
if [ -d "/proc/${LINE}" ]; then | ||
echo "Killing $2 process ${LINE}" | ||
kill ${LINE} | ||
fi | ||
rm -f ${SERVICE_DIRECTORY}/${PIDFILE} | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
} | ||
|
||
stop() { | ||
killbypid ${FOREVERPID} forever | ||
killbypid ${PIDFILE} hillview-server | ||
} | ||
|
||
status() { | ||
if [ -f ${PIDFILE} ]; then | ||
read LINE < ${SERVICE_DIRECTORY}/${PIDFILE} | ||
if [ -d "/proc/${LINE}" ]; then | ||
echo "Process seems to be running" | ||
return 0 | ||
fi | ||
fi | ||
echo "Could not find running aggregator" | ||
} | ||
|
||
case ${1} in | ||
start) | ||
start | ||
;; | ||
stop) | ||
stop | ||
;; | ||
restart) | ||
stop | ||
start | ||
;; | ||
status) | ||
status | ||
;; | ||
*) | ||
echo "Usage: $0 {start|stop|restart|status}" | ||
esac |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/bin/bash | ||
# This is teamplate for a script that manages a hillview web server as a service. | ||
|
||
#REPLACE_WITH_VARIABLES | ||
|
||
# File storing PID of the hillview worker | ||
PIDFILE="hillview-webserevr.pid" | ||
cd ${SERVICE_DIRECTORY} | ||
|
||
start() { | ||
if [ "x${CLEANUP}" == "x1" ]; then | ||
rm -f hillview-web.log hillview-web.log.* hillview-web.log*.lck | ||
fi | ||
export WEB_CLUSTER_DESCRIPTOR=serverlist | ||
nohup ./${TOMCAT}/bin/startup.sh & | ||
} | ||
|
||
stop() { | ||
if pgrep -f tomcat; then | ||
${SERVICE_DIRECTORY}"/"${TOMCAT}/bin/shutdown.sh | ||
echo Stopped | ||
else | ||
echo "Web server already stopped" | ||
fi | ||
pkill -f Bootstrap | ||
true | ||
} | ||
|
||
status() { | ||
# This assumes there's a single tomcat on the machine, which may not be true... | ||
if ! pgrep -f tomcat; then | ||
echo "Web server not running" | ||
else | ||
echo "Web server running" | ||
fi | ||
true | ||
} | ||
|
||
case ${1} in | ||
start) | ||
start | ||
;; | ||
stop) | ||
stop | ||
;; | ||
restart) | ||
stop | ||
start | ||
;; | ||
status) | ||
status | ||
;; | ||
*) | ||
echo "Usage: $0 {start|stop|restart|status}" | ||
esac |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/bin/bash | ||
# This is teamplate for a script that manages a hillview worker as a service. | ||
|
||
#REPLACE_WITH_VARIABLES | ||
|
||
# File storing PID of the hillview worker | ||
PIDFILE="hillview-worker.pid" | ||
# File storing PID of the forever process that runs the hillview worker | ||
FOREVERPID="forever-worker.pid" | ||
|
||
cd ${SERVICE_DIRECTORY} | ||
|
||
start() { | ||
echo "Starting worker" | ||
if [ "x${CLEANUP}" == "x1" ]; then | ||
rm -f hillview.log hillview.log.* hillview.log*.lck | ||
fi | ||
./forever.sh ${FOREVERPID} nohup java -ea -Dlog4j.configurationFile=./log4j.properties -server -Xmx${HEAPSIZE} -jar ${SERVICE_DIRECTORY}/hillview-server-jar-with-dependencies.jar 0.0.0.0:${WORKER_PORT} >nohup.out 2>&1 & | ||
} | ||
|
||
killbypid() { | ||
local PIDFILE=$1 | ||
if [ -f ${PIDFILE} ]; then | ||
# First try to find the service pid | ||
read LINE < ${SERVICE_DIRECTORY}/${PIDFILE} | ||
if [ -d "/proc/${LINE}" ]; then | ||
echo "Killing $2 process ${LINE}" | ||
kill ${LINE} | ||
fi | ||
rm -f ${SERVICE_DIRECTORY}/${PIDFILE} | ||
return 0 | ||
else | ||
return 1 | ||
fi | ||
} | ||
|
||
stop() { | ||
killbypid ${FOREVERPID} forever | ||
killbypid ${PIDFILE} hillview-server | ||
if [ $? -ne 0 ]; then | ||
# Kill it by name; may have collateral damage | ||
if pgrep -f hillview-server; then | ||
pkill -f hillview-server | ||
echo "Stopped" | ||
else | ||
echo "Already stopped" | ||
fi | ||
fi | ||
true | ||
} | ||
|
||
status() { | ||
if [ -f ${PIDFILE} ]; then | ||
read LINE < ${PIDFILE} | ||
if [ -d "/proc/${LINE}" ]; then | ||
echo "Process seems to be running" | ||
return 0 | ||
fi | ||
fi | ||
echo "Could not find running worker" | ||
} | ||
|
||
case ${1} in | ||
start) | ||
start | ||
;; | ||
stop) | ||
stop | ||
;; | ||
restart) | ||
stop | ||
start | ||
;; | ||
status) | ||
status | ||
;; | ||
*) | ||
echo "Usage: $0 {start|stop|restart|status}" | ||
esac |
Oops, something went wrong.