#!/bin/sh
#
# Start chrony if enabled by flag

CHRONY_IS_ENABLED=/data/chrony_is_enabled

[ -r /etc/default/chrony ] && . /etc/default/chrony

case "$1" in
  start)
    if [ -e "$CHRONY_IS_ENABLED" ]; then
      printf "Starting chrony: "
      chronyd $CHRONY_ARGS && echo "OK" || echo "FAIL"
    else
      echo "Not starting chrony. It is not enabled."
    fi
    ;;
  stop)
    if [ -e "$CHRONY_IS_ENABLED" ]; then
      printf "Stopping chrony: "
      killall chronyd && echo "OK" || echo "FAIL"
    else
      echo "Not stopping chrony. It is not enabled."
    fi
    ;;
  restart|reload)
    "$0" stop
    sleep 1
    "$0" start
    ;;
  *)
    echo "Usage: $0 {start|stop|restart}"
    exit 1
esac

exit $?
