Created
October 17, 2019 13:36
-
-
Save dominijk/347ff379605d9e56899c4ef1bc749051 to your computer and use it in GitHub Desktop.
AWS EC2 Initd for Geoserver 2.15.2
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
#!/bin/sh | |
### BEGIN INIT INFO | |
# Provides: GeoServer | |
# Required-Start: $local_fs $network $named $time $syslog | |
# Required-Stop: $local_fs $network $named $time $syslog | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Description: Starts and stops the GeoServer, which should be located at /usr/share/geoserver | |
### END INIT INFO | |
SERVICE_NAME=geoserver | |
START=/usr/share/geoserver/bin/startup.sh | |
STOP=/usr/share/geoserver/bin/shutdown.sh | |
RUNAS=ec2-user | |
GEOSERVER_HOME=/usr/share/geoserver/ | |
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.222.b10-1.el7_7.x86_64 | |
#I've installed 1.8.0_222 which is teseted as working with Geoserver but not tested as working with this Daemon on the development | |
#PIDFILE=/var/run/geoserver.pid | |
PIDFILE=/run/geoserver.pid | |
LOGFILE=/var/log/geoserver/geoserver.log | |
start() { | |
if [ -f /run/$PIDNAME ] && kill -0 $(cat /run/$PIDNAME); then | |
echo "$SERVICE_NAME is already running" >&2 | |
return 1 | |
fi | |
echo "Starting $SERVICE_NAME..." >&2 | |
su -c "GEOSERVER_HOME=$GEOSERVER_HOME JAVA_HOME=$JAVA_HOME $START &> '$LOGFILE' & echo \$!" $RUNAS > "$PIDFILE" | |
echo "$SERVICE_NAME is started" >&2 | |
} | |
stop() { | |
if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then | |
echo "$SERVICE_NAME is not running" >&2 | |
if [ -f "$PIDFILE" ]; then | |
echo "Removing $PIDFILE" | |
rm $PIDFILE | |
fi | |
return 1 | |
fi | |
echo "Stopping $SERVICE_NAME..." >&2 | |
su -c "$STOP &> '$LOGFILE' & echo \$!" $RUNAS && kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE" | |
echo "$SERVICE_NAME has stopped" >&2 | |
} | |
status() { | |
printf "%-50s" "Checking $SERVICE_NAME..." | |
if [ -f $PIDFILE ]; then | |
PID='cat $PIDFILE' | |
if [ -z "'ps axf | grep ${PID} | grep -v grep'" ]; then | |
printf "%s\n" "Process dead but pidfile exists" | |
exit 1 | |
else | |
echo "$SERVICE_NAME is running" | |
fi | |
else | |
printf "%s\n" "$SERVICE_NAME is not running" | |
exit 3 | |
fi | |
} | |
case "$1" in | |
status) | |
status | |
;; | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart) | |
stop | |
start | |
;; | |
*) | |
echo "Usage: $0 {start|restart|status|stop}" | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment