Skip to content

Commit

Permalink
Add STOP_TIMEOUT to init script + remove restart from init provider
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamrad117 committed Mar 2, 2018
1 parent 992bcb7 commit 268389a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
2 changes: 1 addition & 1 deletion providers/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
source 'init.erb'
mode '0755'
variables(vars)
notifies :restart, resources(service: "#{service_name}")
# notifies :restart, resources(service: "#{service_name}")
end
end
42 changes: 34 additions & 8 deletions templates/default/init.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ DEFAULT_CQ_CONTEXT=<%= @default_context %>

CQ_RUNNABLE_JAR=<%= @runnable_jar %>

STOP_TIMEOUT=300
FORCE=n

#---------------------------------------------------------------------
# Don't edit below here
#---------------------------------------------------------------------
Expand Down Expand Up @@ -74,6 +77,11 @@ Other options
--help, -h show this help
--max-files sets the ulimit for max open files before executing the jvm.
default is 8192
Stop/Restart options
--force, -f stop will be done using SIGKILL. If specified - timeout option wont work.
--timeout, -t sets stop timeout in secconds. Default 300. If timeout reached but
aem not stopped - SIGKILL will be used.
@@
}

Expand Down Expand Up @@ -122,6 +130,8 @@ initDefaults() {
export NOFORK_OPT
QUICKSTART_OPTS="${QUICKSTART_OPTS:-$NOFORK_OPT}"
export QUICKSTART_OPTS
export STOP_TIMEOUT
export FORCE
}

# echo to stderr and to the log file
Expand Down Expand Up @@ -254,6 +264,12 @@ findRunnableJar() {
initDefaults
while [ -n "$1" ]; do
case "$1" in
'--force' | '-f')
FORCE=y
;;
'--timeout' | '-t')
STOP_TIMEOUT=$2
shift;;
'--context')
CQ_CONTEXT=$2
shift;;
Expand Down Expand Up @@ -545,8 +561,13 @@ server=y,suspend=${CQ_JVM_DEBUG_SUSPENDED}"
exit 0;
fi

printf "stopping..."
$KILL $cqpid; status=$?
if [ "$FORCE" = y ]; then
printf "FORCE SIGKILL stopping..."
$KILL -9 $cqpid; status=$?
else
printf "stopping..."
$KILL $cqpid; status=$?
fi

if [ $status -eq 1 ]; then
echo "Unable to kill process $cqpid"
Expand All @@ -555,23 +576,28 @@ server=y,suspend=${CQ_JVM_DEBUG_SUSPENDED}"

COUNTER=0
# AEM6 takes a very long time to stop after the first run. Subsequent stops are usually much quicker.
TIMEOUT_SECONDS=300
while ps -p $cqpid > /dev/null 2>&1 && [ $COUNTER -lt ${TIMEOUT_SECONDS} ]; do
while ps -p $cqpid > /dev/null 2>&1 && [ $COUNTER -lt ${STOP_TIMEOUT} ]; do
printf "."
COUNTER=`expr $COUNTER + 1`
COUNTER=`expr $COUNTER + 2`
sleep 2
done
if ps -p $cqpid > /dev/null 2>&1; then
echo "Process $cqpid still running, unable to stop"
exit 20
echo "Process $cqpid still running, Using 'kill -9'"
$KILL -9 $cqpid; status=$?
else
echo "stopped."
rm -f "$CQ_LOGDIR/cq.pid"
fi
;;
#---------------------------------------------------------------------
'restart')
"$0" stop
arguments=" -t $STOP_TIMEOUT"

if [ "$FORCE" = y ]; then
arguments="$arguments -f"
fi

"$0" stop $arguments
"$0" start
;;
#---------------------------------------------------------------------
Expand Down

1 comment on commit 268389a

@vgirnet
Copy link

@vgirnet vgirnet commented on 268389a Mar 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing restart from provider will break the changes in case of any AEM version change, or some other attributes changes.

Please sign in to comment.