Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,29 @@ Format:
Specifies from and to versions which are supported by the
in-place-upgrade mechanism.

aem_cms_stop_timeout_seconds: 1200

Seconds to wait for instance to be stopped until process is killed.

aem_cms_systemd_unit_template: "aem.service.j2"

Path to the systemd unit template. Use this variable to specify a custom
template.

aem_cms_sysvinit_service_template: "aem.init.j2"

Path to the sysvinit service template. Path to the systemd unit
template. Use this variable to specify a custom template.

aem_cms_stop_sync_template: "stop-sync.sh.j2"

Path to the synchronous stop script template. Use this variable to
specify a custom template.

aem_cms_stop_sync_path: "{{ aem_cms_home }}/crx-quickstart/bin/stop-sync.sh"

Destination path of the synchronous stop script on the instance.

## Dependencies

This role depends on the
Expand Down
15 changes: 15 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,18 @@ aem_cms_in_place_upgrade_paths:
- "6.4.0"
# "from_version":
# - "to_version" # list of versions that an upgrade is allowed for

# Seconds to wait for instance to be stopped until process is killed
aem_cms_stop_timeout_seconds: 1200

# Path to the systemd unit template
aem_cms_systemd_unit_template: "aem.service.j2"

# Path to the sysvinit service template
aem_cms_sysvinit_service_template: "aem.init.j2"

# Path to the synchronous stop script template
aem_cms_stop_sync_template: "stop-sync.sh.j2"

# Destination path of the synchronous stop script on the instance
aem_cms_stop_sync_path: "{{ aem_cms_home }}/crx-quickstart/bin/stop-sync.sh"
8 changes: 8 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@
state: absent
when: aem_cms_remove_download

- name: Create stop-sync shell file.
template:
src: "{{ aem_cms_stop_sync_template }}"
dest: "{{ aem_cms_stop_sync_path }}"
owner: "{{ aem_cms_user }}"
group: "{{ aem_cms_group }}"
mode: "0744"

- name: Setup AEM systemd unit.
include_tasks: systemd.yml
when: ansible_service_mgr == 'systemd'
Expand Down
2 changes: 1 addition & 1 deletion tasks/systemd.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- name: Create AEM systemd unit file.
template:
src: aem.service.j2
src: "{{ aem_cms_systemd_unit_template }}"
dest: "/etc/systemd/system/{{ aem_cms_service_name }}.service"
mode: "0644"

Expand Down
2 changes: 1 addition & 1 deletion tasks/sysvinit.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- name: Create AEM initd service file.
template:
src: aem.init.j2
src: "{{ aem_cms_sysvinit_service_template }}"
dest: "/etc/init.d/{{ aem_cms_service_name }}"
mode: "0755"

Expand Down
128 changes: 63 additions & 65 deletions templates/aem.init.j2
Original file line number Diff line number Diff line change
@@ -1,65 +1,63 @@
#!/bin/sh -e
### BEGIN INIT INFO
# Provides: {{ aem_cms_service_name }}
# Required-Start: $local_fs $remote_fs $network $syslog $named
# Required-Stop: $local_fs $remote_fs $network $syslog $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start AEM process
# Description: Init script for AEM instance {{ aem_cms_service_name }}
### END INIT INFO

# Source function library.
#. /etc/rc.d/init.d/functions
. /lib/lsb/init-functions

SCRIPT_NAME=`basename $0`
AEM_ROOT={{ aem_cms_home }}
AEM_USER={{ aem_cms_user }}


########
BIN=${AEM_ROOT}/crx-quickstart/bin
START=${BIN}/start
STOP="${BIN}/stop --sync"
STATUS="${BIN}/status"

aem_start() {
if $0 status > /dev/null ; then
log_success_msg "$SCRIPT_NAME already started"
else
log_daemon_msg "Starting $DESC" "$SCRIPT_NAME"
su - ${AEM_USER} ${START} > /dev/null
log_end_msg 0
fi
}

aem_stop() {
if $0 status > /dev/null ; then
log_daemon_msg "Stopping $DESC" "$SCRIPT_NAME"
su - ${AEM_USER} -c "bash ${STOP}" > /dev/null
log_end_msg 0
else
log_success_msg "$SCRIPT_NAME not started"
fi
}

case "$1" in
start)
aem_start
;;
stop)
aem_stop
;;
status)
su - ${AEM_USER} ${STATUS}
;;
restart)
aem_stop
aem_start
;;
*)
echo "Usage: $SCRIPT_NAME {start|stop|status|restart}"
exit 1
;;
esac
#!/bin/bash
### BEGIN INIT INFO
# Provides: {{ aem_cms_service_name }}
# Required-Start: $local_fs $remote_fs $network $syslog $named
# Required-Stop: $local_fs $remote_fs $network $syslog $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start AEM process
# Description: Init script for AEM instance {{ aem_cms_service_name }}
### END INIT INFO

# Source function library.
. /lib/lsb/init-functions

SCRIPT_NAME=`basename $0`
AEM_ROOT={{ aem_cms_home }}
AEM_USER={{ aem_cms_user }}
PID_PATH={{ aem_cms_home }}/crx-quickstart/conf/cq.pid
STOP_TIMEOUT_SECONDS={{ aem_cms_stop_timeout_seconds }}


########
BIN=${AEM_ROOT}/crx-quickstart/bin
START=${BIN}/start
STOP=${BIN}/stop-sync.sh
STATUS="${BIN}/status"

aem_start() {
pidResult=$(pgrep --pidfile $PID_PATH || true);
if [[ $pidResult != "" ]];
then
log_success_msg "$SCRIPT_NAME already started"
else
log_daemon_msg "Starting $SCRIPT_NAME"
su - ${AEM_USER} ${START} > /dev/null
log_end_msg 0
fi
}

aem_stop() {
# execute sync stop script
su - ${AEM_USER} -c "bash ${STOP}"
}

case "$1" in
start)
aem_start
;;
stop)
aem_stop
;;
status)
su - ${AEM_USER} ${STATUS}
;;
restart)
aem_stop
aem_start
;;
*)
echo "Usage: $SCRIPT_NAME {start|stop|status|restart}"
exit 1
;;
esac
25 changes: 21 additions & 4 deletions templates/aem.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,28 @@ Requires=network.target

[Service]
Type=forking
ExecStart={{ aem_cms_home }}/crx-quickstart/bin/start
ExecStop={{ aem_cms_home }}/crx-quickstart/bin/stop --sync
PIDFile={{ aem_cms_home }}/crx-quickstart/conf/cq.pid
User={{ aem_cms_user }}

LimitNOFILE={{ aem_cms_limit_nofile }}

User={{ aem_cms_user }}
Group={{ aem_cms_group }}

# Do not kill the process because sync stop script is taking care of this
KillMode=none

ExecStart={{ aem_cms_home }}/crx-quickstart/bin/start

# sleep some time after start to ensure pid file is present for systemd
ExecStartPost=/bin/sleep 5s
ExecStop=-{{ aem_cms_stop_sync_path }}

# Configure the time to wait for ExecStop command
{# Add 30 seconds to aem_cms_stop_timeout_seconds to avoid timeouts when process is killed #}
TimeoutStopSec={{ aem_cms_stop_timeout_seconds | int + 30}}s

# Wait at least one second before restart
RestartSec=1

[Install]
WantedBy=multi-user.target
WantedBy=multi-user.target
46 changes: 46 additions & 0 deletions templates/stop-sync.sh.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash
# Source function library.
. /lib/lsb/init-functions

SCRIPT_NAME=`basename $0`
AEM_ROOT={{ aem_cms_home }}
AEM_SERVICE_NAME={{ aem_cms_service_name }}
PID_PATH=${AEM_ROOT}/crx-quickstart/conf/cq.pid
STOP_TIMEOUT_SECONDS={{ aem_cms_stop_timeout_seconds }}

########
BIN=${AEM_ROOT}/crx-quickstart/bin
STOP=${BIN}/stop

# check if instance is running
pidResult=$(pgrep --pidfile $PID_PATH || true);
if [[ $pidResult != "" ]];
then
# AEM is running
log_daemon_msg "Stopping $AEM_SERVICE_NAME"
bash ${STOP} > /dev/null
while [ "$STOP_TIMEOUT_SECONDS" != "0" ]; do
sleep 1s
pidResult=$(pgrep --pidfile $PID_PATH || true);
if [[ $pidResult == "" ]];
then
break;
fi

log_progress_msg "."
let STOP_TIMEOUT_SECONDS-=1;

done
# check if AEM process has to be terminated
pidResult=$(pgrep --pidfile $PID_PATH || true);
if [[ $pidResult != "" ]];
then
log_daemon_msg "Killed $AEM_SERVICE_NAME because shutdown timeout was reached"
kill -9 $(cat $PID_PATH);
fi
log_end_msg 0
else
# AEM is not running
log_success_msg "$AEM_SERVICE_NAME already stopped"
log_end_msg 7
fi