#!/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 ### 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. ### END INIT INFO export PATH=/sbin:/bin:/usr/sbin:/usr/bin THIS_FILE=${0##*/} VERSION=1.1.0 AUTHOR_NAME=imacat AUTHOR_MAIL=imacat@mail.imacat.idv.tw DESC="SNTP client for Virtual PC" THIS_CONF=/etc/default/vsntp # source the configuration test -e $THIS_CONF && . $THIS_CONF 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 # default values -- do not change anything here _DEF_SYNC_INTERVAL=900 _DEF_SCHEDULER=-s # 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" OPTS="$OPTS $SERVER" # sanity checks if test ! -n "$SERVER"; then echo "$THIS_FILE: You must set the SERVER in $THIS_CONF" >&2 exit 1 fi if test ! -x $BIN_PATH; then echo "$THIS_FILE: Missing valid daemon program at $BIN_PATH" >&2 exit 1 fi if test -n "$USER" -a ! "$USER" = "root"; then echo "$THIS_FILE: You need to be root to run this script." >&2 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 RETVALS=$? test $RETVALS = 0 || { echo -n ":failed"; RETVAL=$RETVALS; } echo "." return $RETVAL } stop () { echo -n "Stopping $DESC:" RETVAL=0 echo -n " $BIN_NAME" start-stop-daemon --stop --quiet \ --pidfile $PID_FILE --name $BIN_NAME --user $RUN_USER --exec $BIN_PATH RETVALS=$? test $RETVALS = 0 || { echo -n ":failed"; RETVAL=$RETVALS; } rm -f $PID_FILE 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 RETVALS=$? if test $RETVALS = 0; then echo "$DESC $BIN_NAME is up and running ($(<$PID_FILE))." else echo "$DESC $BIN_NAME is not running (or some problem may exists)." 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} 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. Report bugs to $AUTHOR_NAME <$AUTHOR_MAIL> EOF exit 0 ;; -v|--version) cat << EOF $THIS_FILE version $VERSION by $AUTHOR_NAME <$AUTHOR_MAIL> EOF exit 0 ;; *) echo "$THIS_FILE: unrecognized argument: $1" >&2 echo "Try \`$THIS_FILE --help' for more information" >&2 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 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