Skip to content

Commit

Permalink
updating autoreboot script
Browse files Browse the repository at this point in the history
  • Loading branch information
pvisweswar committed Sep 5, 2023
1 parent e3a7508 commit 8e31dc4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/commcare_cloud/ansible/roles/devops_scripts/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@
mode: "u=rwx,g=rwx,o=r"
when: "'postgresql' in group_names or 'citusdb' in group_names or 'pg_standby' in group_names"

- name: Copy uptime.sh script to /usr/local/sbin
- name: Copy autoreboot.sh script to /usr/local/sbin
template:
src: uptime.sh.j2
dest: /usr/local/sbin/uptime.sh
src: autoreboot.sh.j2
dest: /usr/local/sbin/autoreboot.sh
owner: ansible
group: ansible
mode: "u=rwx,g=rwx,o=r"
when: "'formplayer' in group_names or 'webworkers' in group_names"

- name: Creates a cron to check the uptime details
- name: Creates a cron to check the autoreboot details
become: yes
cron:
name: Run uptime for every 0th minute and 30th minute
name: Run autoreboot.sh for every 0th minute and 30th minute
minute: "0,30"
hour: "*"
day: "*"
month: "*"
weekday: "*"
user: root
job: "/usr/local/sbin/uptime.sh"
cron_file: uptime_sh
job: "/usr/local/sbin/autoreboot.sh"
cron_file: autoreboot_sh
when: maintenance_time is defined and ("'formplayer' in group_names or 'webworkers' in group_names")

- name: Copy intruder.sh script to /usr/local/sbin
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

current_availability_zone=$(ec2metadata --availability-zone | awk -F'-' '{print $3}')
maintenance_time={{ maintenance_time }}
current_time=$(date +%R)
uptime_days=$(uptime | awk '/days?/ {print $3; next}; {print 0}')

if [ $uptime_days -ge 90 ] && [[ $current_time > $maintenance_start_time ]] && [[ $current_time < $maintenance_last_time ]]; then
if [ "$current_availability_zone" == "1a" ]; then
logger '[Maintenance] Rebooting server as uptime is greater than or equal to ninety days in az:A'
echo "Starting reboot"
shutdown -r +1
elif [ "$current_availability_zone" == "1b" ]; then
logger '[Maintenance] Rebooting server as uptime is greater than or equal to ninety days in az:B'
echo "Starting reboot"
shutdown -r +30
elif [ "$current_availability_zone" == "1c" ]; then
logger '[Maintenance] Rebooting server as uptime is greater than or equal to ninety days in az:C'
echo "Starting reboot"
shutdown -r +60
fi
fi

0 comments on commit 8e31dc4

Please sign in to comment.