SliTaz SliTaz Forum

You are not logged in.

#1 2013-06-13 11:19:26

emgi
Member
Registered: 2012-12-17
Posts: 127

Fix for ntp init script in 4.0

This is a fix to an issue in Slitaz 4.0 with the /etc/init.d/ntp script.

The problem is essentially cosmetic but still nice to have fixed.

Problem description:

It is possible to start the ntp daemon (/usr/bin/ntpd) using the script from /etc/init.d/ when used during boot or manually to start ntpd the very first time.

Syntax: [c]/etc/init.d/ntp start[/c]

However, when using the script with either stop or restart, it fails:

[c]# /etc/init.d/ntp restart
ntp is not running.
#[/c]
Successive starts will result in multiple instances of the daemon being started. (not good)

When investigating the root cause of this problem it turned out that the start sequence omits to write the pid file to /var/run/. Once the process is started for the first time, everything else fails because this file is what all sections of the script are checking for.

Solution:

The fix is to add a line writing the PID file to both the start and restart sections. I did this using pgrep. Presumably this task was supposed to be handled by a redundant line in the beginning of the script: [c][ -n "$OPTIONS" ] || OPTIONS="-p $PIDFILE -c /etc/ntp.conf"[/c]

This line seems to have been disfunctional; my version works correctly without it.

I have also changed [c]$NAME[/c] to ntpd instead of ntp and the description [c]$DESC[/c] to ntp daemon instead of ntp server.

To install this fix, you should replace the existing /etc/init.d/ntp with the below version.

(Tried to create an attachment but failed)

/emgi

[c]#!/bin/sh
# /etc/init.d/ntp : Start, stop and restart ntp server on SliTaz, at
# boot time or with the command line.
#
# To start ntp server at boot time, just put ntp in the $RUN_DAEMONS
# variable of /etc/rcS.conf and configure options with /etc/daemons.conf
# version 1.1 jun 2013
#
. /etc/init.d/rc.functions
. /etc/daemons.conf

NAME=ntpd
DESC="ntp daemon"
DAEMON=/usr/bin/ntpd
OPTIONS=$NTP_OPTIONS
PIDFILE=/var/run/ntpd.pid

case "$1" in
  start)
    if active_pidfile $PIDFILE ntpd ; then
      echo "$NAME already running."
      exit 1
    fi
    echo -n "Starting $DESC: $NAME... "
    $DAEMON $OPTIONS
    pgrep $DAEMON > $PIDFILE
    status
    ;;
  stop)
    if ! active_pidfile $PIDFILE ntpd ; then
      echo "$NAME is not running."
      exit 1
    fi
    echo -n "Stopping $DESC: $NAME... "
    kill $(cat $PIDFILE)
    rm $PIDFILE
    status
    ;;
  restart)
    if ! active_pidfile $PIDFILE ntpd ; then
      echo "$NAME is not running."
      exit 1
    fi
    echo -n "Restarting $DESC: $NAME... "
    kill $(cat $PIDFILE)
    $DAEMON $OPTIONS
    pgrep $DAEMON > $PIDFILE
    status
    ;;
  *)
    echo ""
    echo -e "33[1mUsage:33[0m /etc/init.d/$(basename $0) [start|stop|restart]"
    echo ""
    exit 1
    ;;
esac

exit 0[/c]

Offline

#2 2013-06-14 06:32:30

emgi
Member
Registered: 2012-12-17
Posts: 127

Re: Fix for ntp init script in 4.0

Just noticed a problem with the pasted file above.

Characters got lost while pasting. :-(

cat $PIDFILE should be surrounded by [c]like this: kill[/c]cat $PIDFILE`

Sorry for the inconvenience.

/emgi

Offline

#3 2013-06-14 09:17:01

emgi
Member
Registered: 2012-12-17
Posts: 127

Re: Fix for ntp init script in 4.0

Still no good, the message is not displayed exactly as I typed it; the quotes go missing...

Anyway, another finding is that the problem also has been fixed in the cooking version of ntp, which is ntp-4.2.6p5.tazpkg. The version in 4.0 is ntp-4.2.6p3.tazpkg.

You can download & install the cooking version in 4.0.

Next time I will check this first, before suggesting any changes.

/emgi

Offline

#4 2013-06-14 10:03:49

lexeii
Administrator
Registered: 2012-03-21
Posts: 1,853

Re: Fix for ntp init script in 4.0

emgi,

Next time I will check this first, before suggesting any changes.

smile

Pascal Bellard tells you "Thanks!" in commits that fixed ntp: http://hg.slitaz.org/wok/rev/e1f16de14d6e http://hg.slitaz.org/wok-stable/rev/66108539473c

Thank you for being paid attention and offered a solution!

I edited your very first post in this topic. Please, look at bottom of this page:

forum-markup.png

Backticks have special meaning on this forum.

In the shell scripts here is equivalents:

[c]1) variable=‘some code‘          # imagine here backticks smile
2) variable=$(some code)[/c]
Please, use the second variant in your scripts. It is more obvious, admits an embedding, and does not conflict with forum markup.

Offline

#5 2013-06-14 10:46:36

emgi
Member
Registered: 2012-12-17
Posts: 127

Re: Fix for ntp init script in 4.0

Hi Aleksej,

I understand it now that the backticks have a special meaning. Quick solutions tend to be dirty ones. ;-) I wasn't intending to post the file as text in the first place. This became necessary because I was unable to create an attachment. I guess you need special authorization for that? You seem to be able to do it but when I try I get a 'denied' message.

So now I understand Pascal immediately implemented my proposed fix. (Do you guys ever need to sleep?)

This kind of thing is one of the few I can contribute to and its good to know this is appreciated.

BTW: I have also updated the System Adminstration section of the Handbook regarding ntp.

/emgi

Offline

Registered users online in this topic: 0, guests: 1
[Bot] ClaudeBot

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.016 seconds, 7 queries executed - Memory usage: 1.54 MiB (Peak: 1.77 MiB) ]