I'm trying to create a template for scripts of start
and stop
services.
I was checking the template for tomcat
start and stop and see the command RETVAL=$?
.
What this does ? Should I keep it ? By the way, my script it's below in case you guys wanna see it.
#!/bin/bash
#===================================================================================
#
#
FILE: <script-file-name>.sh
#
#
USAGE: <script-file-name>.sh [-d] [-l] [-oD logfile] [-h] [starting directories]
#
# DESCRIPTION: List and/or delete all stale links in directory trees.
#
The default starting directory is the current directory.
#
Don’t descend directories on other filesystems.
#
#
OPTIONS: see function ’usage’ below
# REQUIREMENTS: ---
#
BUGS: ---
#
NOTES: ---
#
AUTHOR: Valter Henrique, valter.henrique@<company>.com
#
COMPANY: <company>
#
VERSION: 1.0
#
CREATED: 03.14.13
#
REVISION: 03.14.13
#===================================================================================
#
# chkconfig: 345 90 12
# description: <service-name> start, stop, restart service
#
# Get function from functions library
. /etc/init.d/functions
folder=/<company>/<service-folder> #folder to the application
service="<service-name>" #name of the service
startup=$folder/start.sh
shutdown=$folder/stop.sh
#=== FUNCTION ================================================================
#
NAME: start
# DESCRIPTION: Start the service <service-name>
# PARAMETER 1: ---
#===============================================================================
start() {
#----------------------------------------------------------------------
# logging the start
#----------------------------------------------------------------------
initlog -c "echo -n Starting $service:"
#----------------------------------------------------------------------
# getting the process PID
#----------------------------------------------------------------------
pid_process=`ps -ef | grep "$folder/<jar>.jar" | grep -v grep |awk -F' ' '{ print $2 }'`;
if [ $pid_process ]; then
echo "<service-name> is running!"
echo "Stop then first!"
else
action $"Starting <service-name> service: " su - <user_deployer> -c $startup
RETVAL=$?
fi
#----------------------------------------------------------------------
# create the lock file
#----------------------------------------------------------------------
touch /var/lock/subsys/$service
success $"Sucess $service startup"
echo
}
#=== FUNCTION ================================================================
#
NAME: stop
# DESCRIPTION: Stop the service <service-name>
# PARAMETER 1: ---
#===============================================================================
stop() {
#----------------------------------------------------------------------
# logging the stop
#----------------------------------------------------------------------
initlog -c "echo -n Stopping $service: "
killproc $service
#----------------------------------------------------------------------
# now, delete the lock file
#----------------------------------------------------------------------
rm -f /var/lock/subsys/$service
echo
}
#----------------------------------------------------------------------
# Main Logic
#----------------------------------------------------------------------
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $service
;;
restart|reload|condrestart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac
exit 0
The retval command will set the global return value to the numeric value given. This can be used to pass a value back from a script. The value is initialized to zero whenever a script is executed, so that zero is the default return value.
The Retval class represents the result of a replay operation. There are three types of constructors. The first uses only an error code like OK, error, and so on. For example, JavaList. Select may return OK, out of range, item not found, and so on.
$?
gives the status of the last command executed. In your case, the last command executed was action....
. The exit status of this command will be present in $?
which is later captured in the RETVAL
variable.
If the command was successful, $?
will contain 0, else a non-zero value.
RETVAL is a variable. $? is assigning the status of the last executed command to the RETVAL variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With