Skip to content

Commit

Permalink
Remove daemon mode
Browse files Browse the repository at this point in the history
  • Loading branch information
rrthomas committed Jul 10, 2023
1 parent e225ee7 commit f7b0488
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 156 deletions.
3 changes: 2 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ repository history](https://github.com/ddclient/ddclient/commits/master).

### Breaking changes

* ddclient no longer runs as a daemon. Running via cron is recommended.
* ddclient now requires curl.
* ddclient no longer has built-in support for IP detection via routers and
firewalls.
* ddclient no longer ships any example files for init systems that use `/etc/init.d`.
This was done because those files where effectively unmaintained, untested by the developers and only updated by downstream distros.
If you where relying on those files, please copy them into your packaging.
If you were relying on those files, please copy them into your packaging.
* The defunct `dnsexit` protocol is removed (replaced by `dnsexit2`).

### New features
Expand Down
16 changes: 3 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ start the first time by hand

## TROUBLESHOOTING

1. enable debugging and verbose messages: ``$ ddclient -daemon=0 -debug -verbose -noquiet``
1. enable debugging and verbose messages: ``$ ddclient -debug -verbose -noquiet``

2. Do you need to specify a proxy?
If so, just add a ``proxy=your.isp.proxy`` to the ddclient.conf file.
Expand All @@ -139,14 +139,10 @@ entry with each connection, with:
## configure pppd to update DynDNS with each connection
cp sample-etc_ppp_ip-up.local /etc/ppp/ip-up.local

Alternatively, you may just configure ddclient to operate as a daemon
and monitor your ppp interface.

## USING DDCLIENT WITH `cron`

If you have not configured ddclient to use daemon-mode, you'll need to
configure cron to force an update once a month so that the dns entry will
not become stale.
You'll need to configure cron to force an update every so often so that the
dns entry will not become stale.
## configure cron to force an update twice a month
cp sample-etc_cron.d_ddclient /etc/cron.d/ddclient
Expand Down Expand Up @@ -174,9 +170,6 @@ exit 0
Other DHCP clients may have another method of calling out to programs
for updating DNS entries.
Alternatively, you may just configure ddclient to operate as a daemon
and monitor your ethernet interface.
## USING DDCLIENT WITH `dhclient`
If you are using the ISC DHCP client (dhclient), you can update
Expand All @@ -187,6 +180,3 @@ ie.:
``cp sample-etc_dhclient-exit-hooks /etc/dhclient-exit-hooks``
Edit ``/etc/dhclient-exit-hooks`` to change any options required.
Alternatively, you may just configure ddclient to operate as a daemon
and monitor your ethernet interface.
150 changes: 29 additions & 121 deletions ddclient.in
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ if ($program =~ /test/i) {
my $msgs = '';
my $last_msgs = '';

## If run as *d (e.g., ddclientd) then daemonize by default (but allow
## flags and options to override).
my $daemon_default = ($programd =~ /d$/) ? interval('5m') : 0;

use vars qw($file $lineno);
local $file = '';
local $lineno = '';
Expand All @@ -65,7 +61,6 @@ our %globals;
my ($result, %config, %cache);
my $saved_cache;
my %saved_opt;
my $daemon;
# Control how many times warning message logged for invalid IP addresses
my (%warned_ip, %warned_ipv4, %warned_ipv6);
my $inv_ip_warn_count = opt('max-warn') // 1;
Expand Down Expand Up @@ -163,8 +158,6 @@ sub setv {
}
my %variables = (
'global-defaults' => {
'daemon' => setv(T_DELAY, 0, 0, $daemon_default, interval('60s')),
'foreground' => setv(T_BOOL, 0, 0, 0, undef),
'file' => setv(T_FILE, 0, 0, "$etc/$program.conf", undef),
'cache' => setv(T_FILE, 0, 0, "$cachedir/$program.cache", undef),
'pid' => setv(T_FILE, 0, 0, "", undef),
Expand Down Expand Up @@ -737,15 +730,12 @@ $opt{'list-web-services'} = sub {
my @opt = (
"usage: ${program} [options]",
"options are:",
["daemon", "=s", "-daemon <delay> : run as a daemon, specify <delay> as an interval"],
["foreground", "!", "-foreground : do not fork"],
["proxy", "=s", "-proxy <host> : use <host> as the HTTP proxy"],
["server", "=s", "-server <host> : update DNS information on <host>"],
["protocol", "=s", "-protocol <type> : update protocol used"],
["list-protocols", "", "-list-protocols : print a machine-readable list of supported update protocols and exit. Format: one per line"],
["file", "=s", "-file <path> : load configuration information from <path>"],
["cache", "=s", "-cache <path> : record address used in <path>"],
["pid", "=s", "-pid <path> : record process id in <path> if daemonized"],
"",
["use", "=s", "-use <which> : deprecated, see 'usev4' and 'usev6'"],
&ip_strategies_usage(),
Expand Down Expand Up @@ -829,7 +819,6 @@ sub main {
exit 0;
}

## read config file because 'daemon' mode may be defined there.
read_config($opt{'file'} // default('file'), \%config, \%globals);
init_config();
test_possible_ip() if opt('query');
Expand All @@ -840,80 +829,37 @@ sub main {
$SIG{'HUP'} = sub { $caught_hup = 1; };
$SIG{'TERM'} = sub { $caught_term = 1; };
$SIG{'INT'} = sub { $caught_int = 1; };
# don't fork() if foreground
if (opt('foreground')) {
;
} elsif (opt('daemon')) {
$SIG{'CHLD'} = 'IGNORE';
my $pid = fork;
if ($pid < 0) {
print STDERR "${program}: can not fork ($!)\n";
exit -1;
} elsif ($pid) {
exit 0;
}
$SIG{'CHLD'} = 'DEFAULT';
open(STDOUT, ">/dev/null");
open(STDERR, ">/dev/null");
open(STDIN, "</dev/null");
write_pid();
}

umask 077;
do {
$now = time;
$result = 'OK';
%opt = %saved_opt;
if (opt('help')) {
*STDERR = *STDOUT;
printf("Help found");
}

read_config($opt{'file'} // default('file'), \%config, \%globals);
init_config();
read_cache(opt('cache'), \%cache);
print_info() if opt('debug') && opt('verbose');

fatal("invalid argument '-use %s'; possible values are:\n%s", $opt{'use'}, join("\n", ip_strategies_usage()))
unless exists $ip_strategies{lc opt('use')};
if (defined($opt{'usev6'})) {
usage("invalid argument '-usev6 %s'; possible values are:\n%s", $opt{'usev6'}, join("\n",ipv6_strategies_usage()))
unless exists $ipv6_strategies{lc opt('usev6')};
}

$daemon = opt('daemon');

update_nics();

if ($daemon) {
debug("sleep %s", $daemon);
sendmail();
$now = time;
$result = 'OK';
%opt = %saved_opt;
if (opt('help')) {
*STDERR = *STDOUT;
printf("Help found");
}

my $left = $daemon;
while (($left > 0) && !$caught_hup && !$caught_term && !$caught_int) {
my $delay = $left > 10 ? 10 : $left;
read_config($opt{'file'} // default('file'), \%config, \%globals);
init_config();
read_cache(opt('cache'), \%cache);
print_info() if opt('debug') && opt('verbose');

$0 = sprintf("%s - sleeping for %s seconds", $program, $left);
$left -= sleep $delay;
# preventing deep sleep - see [bugs:#46]
if ($left > $daemon) {
$left = $daemon;
}
}
$caught_hup = 0;
$result = 0;
fatal("invalid argument '-use %s'; possible values are:\n%s", $opt{'use'}, join("\n", ip_strategies_usage()))
unless exists $ip_strategies{lc opt('use')};
if (defined($opt{'usev6'})) {
usage("invalid argument '-usev6 %s'; possible values are:\n%s", $opt{'usev6'}, join("\n",ipv6_strategies_usage()))
unless exists $ipv6_strategies{lc opt('usev6')};
}

} elsif (!scalar(%config)) {
warning("no hosts to update.") unless !opt('quiet') || opt('verbose') || !$daemon;
$result = 1;
update_nics();

} else {
$result = $result eq 'OK' ? 0 : 1;
}
} while ($daemon && !$result && !$caught_term && !$caught_int);
if (!scalar(%config)) {
$result = 1;
} else {
$result = $result eq 'OK' ? 0 : 1;
}

warning("caught SIGINT; exiting") if $caught_int;
unlink_pid();
sendmail();

exit($result);
Expand Down Expand Up @@ -987,8 +933,7 @@ sub update_nics {
# And if it is valid, remember it...
$iplist{$use}{$arg_ip}{$arg_if}{$arg_web}{$arg_cmd} = $ip;
} else {
warning("%s: unable to determine IP address with strategy use=%s", $h, $use)
if !$daemon || opt('verbose');
warning("%s: unable to determine IP address with strategy use=%s", $h, $use);
}
}
# And remember it as the IP address we want to send to the DNS service.
Expand All @@ -1006,8 +951,7 @@ sub update_nics {
# And if it is valid, remember it...
$ipv4list{$usev4}{$arg_ipv4}{$arg_ifv4}{$arg_webv4}{$arg_cmdv4} = $ipv4;
} else {
warning("%s: unable to determine IPv4 address with strategy usev4=%s", $h, $usev4)
if !$daemon || opt('verbose');
warning("%s: unable to determine IPv4 address with strategy usev4=%s", $h, $usev4);
}
}
# And remember it as the IPv4 address we want to send to the DNS service.
Expand All @@ -1025,8 +969,7 @@ sub update_nics {
# And if it is valid, remember it...
$ipv6list{$usev6}{$arg_ipv6}{$arg_ifv6}{$arg_webv6}{$arg_cmdv6} = $ipv6;
} else {
warning("%s: unable to determine IPv6 address with strategy usev6=%s", $h, $usev6)
if !$daemon || opt('verbose');
warning("%s: unable to determine IPv6 address with strategy usev6=%s", $h, $usev6);
}
}
# And remember it as the IP address we want to send to the DNS service.
Expand Down Expand Up @@ -1060,33 +1003,6 @@ sub update_nics {
write_cache(opt('cache'));
}

######################################################################
## unlink_pid()
######################################################################
sub unlink_pid {
if (opt('pid') && opt('daemon')) {
unlink opt('pid');
}
}

######################################################################
## write_pid()
######################################################################
sub write_pid {
my $file = opt('pid');

if ($file && opt('daemon')) {
local *FD;
if (!open(FD, "> $file")) {
warning("Cannot create file '%s'. (%s)", $file, $!);

} else {
printf FD "%s\n", $$;
close(FD);
}
}
}

######################################################################
## write_cache($file)
######################################################################
Expand Down Expand Up @@ -1440,11 +1356,6 @@ sub init_config {

$opt{'timeout'} = 0 if opt('timeout') < 0;

## parse an interval expression (such as '5m') into number of seconds
$opt{'daemon'} = interval(opt('daemon')) if defined($opt{'daemon'});
## make sure the interval isn't too short
$opt{'daemon'} = minimum('daemon') if opt('daemon') > 0 && opt('daemon') < minimum('daemon');

## define or modify host options specified on the command-line
if (exists $opt{'options'} && defined $opt{'options'}) {
## collect cmdline configuration options.
Expand Down Expand Up @@ -2959,15 +2870,12 @@ Global definitions look like:
name=value [,name=value]*
For example:
daemon=5m
use=if, if=eth0
proxy=proxy.myisp.com
protocol=dyndns2
specifies that ${program} should operate as a daemon, checking the
eth0 interface for an IP address change every 5 minutes and use the
'dyndns2' protocol by default. The daemon interval can be specified
as seconds (600s), minutes (5m), hours (1h) or days (1d).
specifies that ${program} should use the 'dyndns2' protocol by
default.
Host definitions look like:
[name=value [,name=value]*]* a.host.domain [,b.host.domain] [login] [password]
Expand Down Expand Up @@ -4937,7 +4845,7 @@ sub nic_freedns_update {
$config{$h}{'mtime'} = $now;
$config{$h}{"status-ipv$ipv"} = 'good';
success("updating %s: update not necessary, '$type' record already set to %s", $h, $ip)
if (!$daemon || opt('verbose'));
if (opt('verbose'));
} else {
my $url = $rec->[2] . "&address=" . $ip;
($url_tmpl = $url) =~ s/\?.*\&/?<redacted>&/; # redact unique update token
Expand Down
2 changes: 1 addition & 1 deletion sample-ddclient-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# ddclient adds the new IP as argument
IP=$1

ddclient -ip ${IP} -file ${SECONDCONFIG} -daemon 0
ddclient -ip ${IP} -file ${SECONDCONFIG}
10 changes: 5 additions & 5 deletions sample-etc_cron.d_ddclient
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
######################################################################
## ddclient is an IP address updater for www.dyndns.org
## ddclient is a dynamic DNS IP address updater
######################################################################
## minute 0-59
## hour 0-23
## day of month 1-31
## month 1-12 (or names, see below)
## day of week 0-7 (0 or 7 is Sun, or use names)
######################################################################
## force an update twice a month (only if you are not using daemon-mode)
## force an update twice a month
##
## 30 23 1,15 * * root /usr/bin/ddclient -daemon=0 -syslog -quiet -force
## 30 23 1,15 * * root /usr/bin/ddclient -syslog -quiet -force
######################################################################
## retry failed updates every hour (only if you are not using daemon-mode)
## retry failed updates every hour
##
## 0 * * * * root /usr/bin/ddclient -daemon=0 -syslog -quiet retry
## 0 * * * * root /usr/bin/ddclient -syslog -quiet retry
2 changes: 1 addition & 1 deletion sample-etc_dhclient-exit-hooks
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ case "$new_ip_address" in
192.168.*) ;;
*)
logger -t dhclient IP address changed to $new_ip_address
ddclient -daemon=0 -syslog -use=ip -ip=$new_ip_address >/dev/null 2>&1
ddclient -syslog -use=ip -ip=$new_ip_address >/dev/null 2>&1
;;
esac
2 changes: 1 addition & 1 deletion sample-etc_dhcpc_dhcpcd-eth0.exe
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ case "$1" in
192.168.*) ;;
*)
logger -t dhcpcd IP address changed to $1
ddclient -daemon=0 -syslog -use=ip -ip=$1 >/dev/null 2>&1
ddclient -syslog -use=ip -ip=$1 >/dev/null 2>&1
;;
esac
2 changes: 1 addition & 1 deletion sample-etc_ppp_ip-up.local
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ case "$IP" in
;;
*) (
sleep 5
ddclient -daemon=0 -syslog -use=if -if=$IFACE >/dev/null 2>&1
ddclient -syslog -use=if -if=$IFACE >/dev/null 2>&1
) &
;;
esac
12 changes: 0 additions & 12 deletions sample-etc_systemd.service

This file was deleted.

0 comments on commit f7b0488

Please sign in to comment.