#!/bin/bash

logger -p local5.debug -i -- `basename $0` $@

# Remove lock file before reboot
rm -f /onapp/reboot.lk

### Reboot ###
# Sync first
# Will attempt to sync all mounted filesystems.
echo s > /proc/sysrq-trigger
for i in 1 2 3 4 5; do

        if dmesg | grep "Emergency Sync complete" > /dev/null; then
                break
        else
                sleep 1
        fi
done

# Remout all FS to RO
# Will attempt to remount all mounted filesystems read-only.
echo u > /proc/sysrq-trigger
for i in 1 2 3 4 5; do

        if dmesg | grep "Emergency Remount complete" > /dev/null; then
                break
        else
                sleep 1
        fi

done

# Reboot server
# Will immediately reboot the system without syncing or unmounting your disks.
echo "Rebooting"
echo b > /proc/sysrq-trigger

exit 0
                                  
