vsntp/init.d/vsntp.redhat

149 lines
3.0 KiB
Plaintext
Raw Normal View History

2021-02-06 08:59:23 +08:00
#!/bin/sh
# start and stop the SNTP client for Virtual PC
# Red Hat styled comments for chkconfig
# chkconfig: 2345 58 74
# description: SNTP client for Virtual PC
# processname: vsntp
# config: /etc/sysconfig/vsntp
# LSB-convention comments
# See: https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Core-generic/LSB-Core-generic/initscrcomconv.html
2021-02-06 08:59:23 +08:00
### BEGIN INIT INFO
# Provides: vsntp
# Required-Start: $network $time
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop the SNTP client for Virtual PC
# Description: vsntp is a SNTP client for Virtual PC that synchronize
# time periodically for systems without hardware RTC.
2021-02-06 08:59:23 +08:00
### END INIT INFO
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
# initialize the environment
THIS_FILE="${0##*/}"
2021-02-06 08:59:23 +08:00
VERSION="1.0.0"
AUTHOR_NAME=imacat
AUTHOR_MAIL=imacat@mail.imacat.idv.tw
2021-02-06 08:59:23 +08:00
lock=/var/lock/subsys/vsntp
# Source function library.
. /etc/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
if [ -f /etc/sysconfig/vsntp ];then
. /etc/sysconfig/vsntp
fi
case "$SCHEDULER" in
alarm|a|-a|--alarm)
SCHEDULER=-a ;;
*)
SCHEDULER=-s ;;
esac
# default values -- do not change anything here
_DEF_SYNC_INTERVAL=900
_DEF_SCHEDULER=-s
2021-02-06 08:59:23 +08:00
RETVAL="0"
OPTIONS=""
test -n "$SCHEDULER" -a "$SCHEDULER" != "$_DEF_SCHEDULER" && OPTIONS="$OPTIONS $SCHEDULER"
test -n "$SYNC_INTERVAL" -a "$SYNC_INTERVAL" != "$_DEF_SYNC_INTERVAL" && OPTIONS="$OPTIONS -i $SYNC_INTERVAL"
2021-02-06 08:59:23 +08:00
OPTIONS="$OPTIONS $SERVER"
# See how we were called.
start() {
echo -n "Starting SNTP client for Virtual PC: "
daemon vsntp $OPTIONS
RETVAL="$?"
echo
[ "$RETVAL" -eq "0" ] && touch $lock
return "$RETVAL"
}
stop() {
echo -n "Stopping SNTP client for Virtual PC: "
killproc vsntp
RETVAL="$?"
echo
[ "$RETVAL" -eq "0" ] && rm -f $lock
return "$RETVAL"
}
rhstatus() {
status vsntp
}
restart() {
stop
start
}
# parse the arguments
while [ "$#" != "0" ]; do
case "$1" in
start|stop|restart|status)
action="$1"
;;
-h|--help)
cat << EOF
Start and/or stop the SNTP client for Virtual PC
Usage: $THIS_FILE {start|stop|restart|status}
2021-02-06 08:59:23 +08:00
start Start the daemon.
stop Stop the daemon.
restart Stop and restart the daemon.
status Display the daemon status
-h,--help Display this help.
-v,--version Display the version information.
2021-02-06 08:59:23 +08:00
Report bugs to $AUTHOR_NAME <$AUTHOR_MAIL>
2021-02-06 08:59:23 +08:00
EOF
exit 0
;;
-v|--version)
cat << EOF
$THIS_FILE v$VERSION by $AUTHOR_NAME <$AUTHOR_MAIL>
2021-02-06 08:59:23 +08:00
EOF
exit 0
;;
*)
echo "$THIS_FILE: unrecognized argument: $1"
echo "Try \`$THIS_FILE --help' for more information"
2021-02-06 08:59:23 +08:00
exit 1
;;
esac
shift
done
# check the arguments
if [ -z "$action" ]; then
cat << EOF
Usage: $THIS_FILE {start|stop|restart|status}
2021-02-06 08:59:23 +08:00
EOF
exit 0
fi
# process now
case "$action" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
rhstatus
;;
esac
exit $?