Skip to content

Instantly share code, notes, and snippets.

@biiont
Created October 1, 2015 08:28
Show Gist options
  • Save biiont/c91e9acc692aceff3e92 to your computer and use it in GitHub Desktop.
Save biiont/c91e9acc692aceff3e92 to your computer and use it in GitHub Desktop.
init.d service for ordinary console app
#!/bin/sh
# This is /etc/sysconfig/someservice:
# CHARTSRVBASE="/opt/someservice"
# CHARTSRVRUN="/opt/someservice"
# CHARTSRVBIN="/opt/someservice/someservice"
# CHARTSRVPID="/var/run/someservice.pid"
# CHARTSRVLOG="/var/log/someservice/someservice-$(date +%Y%m%d%H%M%S).log"
########################################################################
# Begin $rc_base/init.d/
# Description :
# Authors :
# Version : 00.00
# Notes :
########################################################################
. /etc/sysconfig/rc
. ${rc_functions}
. /etc/sysconfig/someservice
NAME="someservice"
CHARTSRVPIDDIR="$(dirname "$CHARTSRVPID")"
CHARTSRVLOGDIR="$(dirname "$CHARTSRVLOG")"
case "${1}" in
start)
boot_mesg "Starting $NAME..."
[ -d "$CHARTSRVPIDDIR" ] || mkdir -p "$CHARTSRVPIDDIR"
[ -d "$CHARTSRVLOGDIR" ] || mkdir -p "$CHARTSRVLOGDIR"
pidofproc -p "${CHARTSRVPID}" "${CHARTSRVBIN}" > /dev/null
case "${?}" in
0)
log_warning_msg "Unable to continue: ${CHARTSRVBIN} is running"
exit 0 # 4
;;
1)
log_warning_msg "Unable to continue: ${CHARTSRVPID} exists"
exit 0 # 4
;;
3)
;;
*)
log_failure_msg "Unknown error code from pidofproc: ${?}"
exit 4
;;
esac
OLD_LD_LIBRARY_PATH="$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH="$CHARTSRVBASE/lib/lib:$CHARTSRVBASE/lib/dashboard:$CHARTSRVBASE/lib/geo:$CHARTSRVBASE/lib/gshhs:$CHARTSRVBASE/lib/property:$CHARTSRVBASE/lib/qpropertyeditor:$CHARTSRVBASE/lib/model:$OLD_LD_LIBRARY_PATH"
OLDWD="$PWD"
cd "$CHARTSRVRUN"
loadproc -f -p "$CHARTSRVPID" /bin/sh -c '"'$CHARTSRVBIN'" '$CHARTSRVARGS' > "'$CHARTSRVLOG'" 2>&1 & echo $! > "'$CHARTSRVPID'"'
cd "$OLDWD"
unset OLDWD
export LD_LIBRARY_PATH="$OLD_LD_LIBRARY_PATH"
unset OLD_LD_LIBRARY_PATH
;;
stop)
boot_mesg "Stopping $NAME..."
killproc -p "$CHARTSRVPID" "$CHARTSRVBIN"
#rm "$CHARTSRVPID"
;;
restart)
${0} stop
sleep 1
${0} start
;;
*)
echo "Usage: ${0} {start|stop|reload|restart|status}"
exit 1
;;
esac
# End $rc_base/init.d/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment