Last active
October 28, 2016 18:11
-
-
Save sloanlance/4d473e2d71d1bc07e2e3217341f7fe04 to your computer and use it in GitHub Desktop.
BASH: Script to determine whether an application is running.
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 -- | |
# File containing the process ID of the application, written by the application | |
PID_FILE='app.pid' | |
# The process name or some string unique to the application's process | |
PROCESS_NAME="java -Dspring.config.location=${HOME}/application.properties" | |
[[ $# -gt 0 && $1 = '-v' ]] && VERBOSE=1 | |
if [[ -f ${PID_FILE} ]]; then | |
[[ ${VERBOSE} ]] && echo "${PID_FILE} found" | |
PID=$(cat "${PID_FILE}") | |
else | |
[[ ${VERBOSE} ]] && echo "${PID_FILE} not found" | |
fi | |
if [[ ! ${PID} ]]; then | |
[[ ${VERBOSE} ]] && echo "No process ID. Searching processes by name." | |
PID=$(pgrep -f "${PROCESS_NAME}") | |
fi | |
if [[ ${PID} ]]; then | |
echo "Running: process ID = ${PID}" | |
exit $(true) | |
else | |
echo 'Not running: process ID not found' | |
exit $(false) | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment