Optware / Optware-ng

279 stars 52 forks source link

DDClient 3.8.3 #160

Closed PiotrC1 closed 8 years ago

PiotrC1 commented 8 years ago

I propose upgrading ddclient to newest version 3.8.3. Also I have modified ddclient startup script to work with optware:

#!/bin/sh
#
# ddclient      This shell script takes care of starting and stopping
#               ddclient.
#
# chkconfig: 2345 65 35
# description: ddclient provides support for updating dynamic DNS services.

CONF=/opt/etc/ddclient/ddclient.conf
program=ddclient

[ -f $CONF ] || exit 0

PID=`ps | grep "$program - sleep" | grep -v grep | awk '{print $1}'`

# PATH=/usr/sbin:/usr/local/sbin:${PATH}
# export PATH

# See how we were called.
case "$1" in
  start)
    # Start daemon.
    DELAY=`grep -v '^\s*#' $CONF | grep -i -m 1 "daemon" | awk -F '=' '{print $2}'`
    if [ -z "$DELAY" ] ; then
        DELAY="-daemon 300"
    else
        DELAY=''
    fi
    echo -n "Starting ddclient: "
    ddclient $DELAY
    echo    
    ;;
  stop)
    # Stop daemon.
    echo -n "Shutting down ddclient: "
    if [ -n "$PID" ] ; then
        kill $PID
    else
        echo "ddclient is not running"
    fi
    echo
    ;;
  restart)
    $0 stop
    $0 start
    ;;
  status)
    if test "$PID"
    then
        for p in $PID
        do
            echo "$program (pid $p) is running"
        done
    else
        echo "$program is stopped"
    fi
    ;;
  *)
    echo "Usage: ddclient {start|stop|restart|status}"
    exit 1
esac

exit 0
alllexx88 commented 8 years ago

I'll look into upgrading it, however this line in the suggested rc script won't do:

PID=`ps | grep "$program - sleep" | grep -v grep | awk '{print $1}'`

It'll work this way only with busybox ps, while procps ps (default for full fledged Linux boxes, and used first in PATH on some devices where Optware-ng runs, like Synology NASes with recent DSM) requires -e flag:

[root@unknown root]$ /opt/bin/procps-ps --help
********* simple selection *********  ********* selection by list *********
-A all processes                      -C by command name
-N negate selection                   -G by real group ID (supports names)
-a all w/ tty except session leaders  -U by real user ID (supports names)
-d all except session leaders         -g by session OR by effective group name
-e all processes                      -p by process ID
T  all processes on this terminal     -s processes in the sessions given
a  all w/ tty, including other users  -t by tty
g  OBSOLETE -- DO NOT USE             -u by effective user ID (supports names)
r  only running processes             U  processes for specified users
x  processes w/o controlling ttys     t  by tty
*********** output format **********  *********** long options ***********
-o,o user-defined  -f full            --Group --User --pid --cols --ppid
-j,j job control   s  signal          --group --user --sid --rows --info
-O,O preloaded -o  v  virtual memory  --cumulative --format --deselect
-l,l long          u  user-oriented   --sort --tty --forest --version
-F   extra full    X  registers       --heading --no-heading --context
                    ********* misc options *********
-V,V  show version      L  list format codes  f  ASCII art forest
-m,m,-L,-T,H  threads   S  children in sum    -y change -l format
-M,Z  security data     c  true command name  -c scheduling class
-w,w  wide output       n  numeric WCHAN,UID  -H process hierarchy
[root@unknown root]$ /opt/bin/procps-ps
  PID TTY          TIME CMD
 7472 pts/1    00:00:00 sh
 7889 pts/1    00:00:00 procps-ps
[root@unknown root]$ /opt/bin/procps-ps -e
  PID TTY          TIME CMD
    1 ?        00:00:01 init
    2 ?        00:00:00 kthreadd
    3 ?        00:00:10 ksoftirqd/0
    4 ?        00:00:00 events/0
    5 ?        00:00:00 khelper
   21 ?        00:00:00 kblockd/0
   24 ?        00:00:00 khubd
   58 ?        00:00:03 kswapd0
   59 ?        00:00:00 aio/0
  101 ?        00:00:02 mtdblockd
  309 ?        00:00:00 hotplug2
  348 ?        00:00:00 buttons
  352 ?        00:00:00 console
  353 ttyS0    00:00:00 sh
  355 ?        00:00:00 jffs2_gcd_mtd3
  359 ?        00:00:00 syslogd
  361 ?        00:00:00 klogd
  398 ?        00:00:00 kmmcd
  489 ?        00:00:00 scsi_eh_0
  490 ?        00:00:17 usb-storage
  507 ?        00:00:00 scsi_eh_1
  508 ?        00:00:00 usb-storage
  745 ?        00:00:00 eapd
  748 ?        00:00:00 nas
  799 ?        00:00:00 telnetd
  802 ?        00:00:00 dropbear
  805 ?        00:00:00 eapd
  808 ?        00:00:00 nas
  811 ?        00:00:01 dnsmasq
  815 ?        00:00:02 httpd
  819 ?        00:00:00 crond
  823 ?        00:00:10 rstats
  826 ?        00:02:53 cstats
  942 ?        00:00:03 kjournald
 3548 ?        00:00:02 pdflush
 4151 ?        00:00:00 cupsd
 4276 ?        00:00:00 dbus-daemon
 7297 ?        00:00:01 dropbear
 7298 pts/0    00:00:00 sh
 7471 ?        00:00:00 dropbear
 7472 pts/1    00:00:00 sh
 7890 pts/1    00:00:00 procps-ps
10747 ?        00:00:00 pdflush

While busybox ps doesn't accept this flag :unamused:

[root@unknown root]$ /opt/bin/busybox ps -e
ps: invalid option -- e
BusyBox v1.23.0 (2016-03-29 21:01:57 PDT) multi-call binary.

Usage: ps

Show list of processes

        w       Wide output
        l       Long output
        T       Show threads

Up till now I've been adding busybox-base dependency to packages that need to know pid, and was using /opt/bin/busybox pidof <name>, since pidof was removed from procps at some point (for some very odd reason if you ask me), but I see it's introduced back by procps-ng project (https://gitlab.com/procps-ng/procps), so I'll be switching to using /opt/bin/procps-pidof.

PiotrC1 commented 8 years ago

Well, I chave checked it only on my TomatoUSB. Thanks for being so carefull.

PiotrC1 commented 8 years ago

Up till now I've been adding busybox-base dependency to packages that need to know pid, and was using /opt/bin/busybox pidof

The problem is that ddclient is written in perl, so /opt/bin/busybox pidof ddclient gives nothing. The only way is to do ps and grep for ddclient.

Originally, in ddclient startup script it was:

PID=`ps -aef | grep "$program - sleep" | grep -v grep | awk '{print $2}'`

but ps by busybox does not accept -aef.

root@Tomato:/opt/etc/init.d# ps --aef ps: invalid option -- a BusyBox v1.23.2 (2015-10-08 20:59:43 CEST) multi-call binary.

Usage: ps

Show list of processes

    w       Wide output
    T       Show threads

So finally it can be something like:

if [ -e /opt/bin/procps-ps ]; then
   PID=`ps -aef | grep "$program - sleep" | grep -v grep | awk '{print $2}'`
else
   PID=`ps | grep "$program - sleep" | grep -v grep | awk '{print $1}'`
fi

instead of

PID=`ps | grep "$program - sleep" | grep -v grep | awk '{print $1}'`
alllexx88 commented 8 years ago

@PiotrC1 You're right, I didn't have the chance to look closer. There's a better way: using pid file and start-stop-daemon. However, I don't really like how ddclient manages pid files, so I plan to patch it a bit to use File::Pid

PiotrC1 commented 8 years ago

Somenthing has changed since last installation - now ddclient cannot be started, because:

root@Tomato:/tmp/mnt# ddclient Use of uninitialized value $pid in chomp at /opt/lib/perl5/site_perl/5.22.1/File/Pid.pm line 175. Use of uninitialized value $pid in chomp at /opt/lib/perl5/site_perl/5.22.1/File/Pid.pm line 175. Can't kill a non-numeric process ID at /opt/lib/perl5/site_perl/5.22.1/File/Pid.pm line 124.

alllexx88 commented 8 years ago

Looks like I haven't tested it good enough. But I do have a fix I'll push tomorrow

PiotrC1 commented 8 years ago

Kudos. Works out of a box.

PiotrC1 commented 8 years ago

Sorry, I have to reopen issue: This is my ddclient.conf file:

daemon=300 # check every 300 seconds syslog=yes # log update msgs to syslog

mail=root # mail all msgs to root

mail-failure=root # mail failed update msgs to root

pid=/opt/var/run/ddclient.pid # record PID in file. Default = /opt/var/run/ddclient.pid

ssl=yes # use ssl-support. Works with

use=web, web=checkip.amazonaws.com, web-skip='IP Address' protocol=dyndns2 server=dynupdate.no-ip.com login=my-login-to-noip password='my-password' mydomain.no-ip.org

And this is what says /opt/etc/init.d/S95ddclient:

root@Tomato:/tmp/home/root# /opt/etc/init.d/S95ddclient start /opt/etc/init.d/S95ddclient: /opt/etc/ddclient/ddclient.conf: line 230: web-skip=IP Address: not found /opt/etc/init.d/S95ddclient: /opt/etc/ddclient/ddclient.conf: line 235: mydomain.no-ip.org: not found Starting DDclient dynamic DNS client

alllexx88 commented 8 years ago

@PiotrC1 Should be fixed now f3d81e981930df7509cb4e5a413d385f63958523

PiotrC1 commented 8 years ago

Thanks. I confirm that it works.