vsntp/init.d/vsntp.debian

183 lines
4.0 KiB
Plaintext
Raw Permalink Normal View History

2021-02-06 08:59:23 +08:00
#!/bin/sh
# start and stop the SNTP client for Virtual PC
# 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
THIS_FILE=${0##*/}
2021-02-06 08:59:23 +08:00
VERSION=1.1.0
AUTHOR_NAME=imacat
AUTHOR_MAIL=imacat@mail.imacat.idv.tw
2021-02-06 08:59:23 +08:00
DESC="SNTP client for Virtual PC"
THIS_CONF=/etc/default/vsntp
2021-02-06 08:59:23 +08:00
# source the configuration
test -e $THIS_CONF && . $THIS_CONF
2021-02-06 08:59:23 +08:00
case "$SCHEDULER" in
alarm|a|-a|--alarm)
SCHEDULER=-a ;;
*)
SCHEDULER=-s ;;
esac
BIN_PATH=/usr/sbin/vsntp
BIN_NAME=${BIN_PATH##*/}
PID_FILE=/var/run/$BIN_NAME.pid
RUN_USER=root
2021-02-06 08:59:23 +08:00
# default values -- do not change anything here
_DEF_SYNC_INTERVAL=900
_DEF_SCHEDULER=-s
2021-02-06 08:59:23 +08:00
# startup options
OPTS=""
test -n "$SCHEDULER" -a "$SCHEDULER" != "$_DEF_SCHEDULER" && OPTS="$OPTS $SCHEDULER"
test -n "$SYNC_INTERVAL" -a "$SYNC_INTERVAL" != "$_DEF_SYNC_INTERVAL" && OPTS="$OPTS -i $SYNC_INTERVAL"
2021-02-06 08:59:23 +08:00
OPTS="$OPTS $SERVER"
# sanity checks
if test ! -n "$SERVER"; then
echo "$THIS_FILE: You must set the SERVER in $THIS_CONF" >&2
2021-02-06 08:59:23 +08:00
exit 1
fi
if test ! -x $BIN_PATH; then
echo "$THIS_FILE: Missing valid daemon program at $BIN_PATH" >&2
2021-02-06 08:59:23 +08:00
exit 1
fi
if test -n "$USER" -a ! "$USER" = "root"; then
echo "$THIS_FILE: You need to be root to run this script." >&2
2021-02-06 08:59:23 +08:00
exit 1
fi
start () {
echo -n "Starting $DESC:"
RETVAL=0
echo -n " $BIN_NAME"
start-stop-daemon --start --startas $BIN_PATH --quiet \
--pidfile $PID_FILE --name $BIN_NAME --user $RUN_USER --exec $BIN_PATH -- $OPTS
2021-02-06 08:59:23 +08:00
RETVALS=$?
test $RETVALS = 0 || { echo -n ":failed"; RETVAL=$RETVALS; }
echo "."
return $RETVAL
}
stop () {
echo -n "Stopping $DESC:"
RETVAL=0
echo -n " $BIN_NAME"
2021-02-06 08:59:23 +08:00
start-stop-daemon --stop --quiet \
--pidfile $PID_FILE --name $BIN_NAME --user $RUN_USER --exec $BIN_PATH
2021-02-06 08:59:23 +08:00
RETVALS=$?
test $RETVALS = 0 || { echo -n ":failed"; RETVAL=$RETVALS; }
rm -f $PID_FILE
2021-02-06 08:59:23 +08:00
echo "."
return $RETVAL
}
restart () {
stop
sleep 1
start
RETVAL=$?
return $RETVAL
}
status () {
RETVAL=0
start-stop-daemon --stop --signal 0 --quiet \
--pidfile $PID_FILE --name $BIN_NAME --user $RUN_USER --exec $BIN_PATH
2021-02-06 08:59:23 +08:00
RETVALS=$?
if test $RETVALS = 0; then
echo "$DESC $BIN_NAME is up and running ($(<$PID_FILE))."
2021-02-06 08:59:23 +08:00
else
echo "$DESC $BIN_NAME is not running (or some problem may exists)."
2021-02-06 08:59:23 +08:00
RETVAL=$RETVALS
fi
return $RETVAL
}
# parse the arguments
while test $# != 0; do
case "$1" in
start|stop|restart|force-reload|status)
action="$1"
;;
-h|--help)
cat << EOF
Start and/or stop the $DESC
Usage: $THIS_FILE {start|stop|restart|force-reload|status}
2021-02-06 08:59:23 +08:00
start Start the daemon.
stop Stop the daemon.
restart Stop and restart the daemon.
force-reload Enforce a reload to the configuration file.
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 version $VERSION by $AUTHOR_NAME <$AUTHOR_MAIL>
2021-02-06 08:59:23 +08:00
EOF
exit 0
;;
*)
echo "$THIS_FILE: unrecognized argument: $1" >&2
echo "Try \`$THIS_FILE --help' for more information" >&2
2021-02-06 08:59:23 +08:00
exit 1
;;
esac
shift
done
# no action specified
if test -z "$action"; then
echo "$THIS_FILE: what do you want to do now?" >&2
echo "Try \`$THIS_FILE --help' for more information" >&2
2021-02-06 08:59:23 +08:00
exit 1
fi
# act now!
case "$action" in
start)
start
RETVAL=$?
;;
stop)
stop
RETVAL=$?
;;
restart|force-reload)
restart
RETVAL=$?
;;
status)
status
RETVAL=$?
;;
esac
exit $RETVAL