Do not add Requires. That will just try to start the network target. Read this: http://www.freedesktop.org/wiki/Softwar … workTarget
One way to do this would be to write a script that keeps on calling wget until it connects (the network is ready) and then writes your IP address to a file.
Thanks for the link. I'd been wondering about the point of network.target.
I'm guessing here... but I could add
Restart=always
into the .service file and in the script:
/* psuedo code */
if wget failed sleep for a second
else sleep for 5 minutes (or so)
Obviously not meeting the robustness the aforementioned link recommends, but a start.
]]>By the way jwm_art, since you experimented a ip change once, maybe also creating a timer service (or a cron job) for repeting the process every few hours would be good
]]>I haven't tested this, but try it:
[Unit]
Description=Obtain public IP address
After=network.target
Requires=network.target
[Service]
Type=oneshot
ExecStart=/bin/bash -c "/usr/bin/wget 'http://whatismyipaddress.com/' -U=msie -O- -q|/bin/sed -n '/LOOKUPADDRESS/ s/.*value=\"\([^\"]*\).*/\1/p' > /tmp/publicip"
[Install]
WantedBy=multi-user.target
Added a line to get the public ip.
EDIT: yeah, he is right, using Requires does not guarantee having an ip. my bad
]]>I'm wanting to use systemd to obtain the my public IP address but it does it before the network is up. I'm using DHCPCD.
I don't want to consider Network Manager, it seems overkill for a desktop machine.
So far, I've created /etc/systemd/system/public-ip.service
[Unit]
Description=Obtain public IP address
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/public_ip.sh /tmp/publicip
[Install]
WantedBy=multi-user.target
and enabled it.
The public_ip.sh script greps the output of wget in order to write the public ip address to the file. The idea here is to use this information within a (popular) system information monitor which updates every second - I don't want to be sending requests to dyndns.org every second to obtain a piece of information which doesn't change? (Hmmm actually, I have experienced it changing during an ssh session IIRC).
Any ideas?
]]>