title: systemd script works but not using curl
body: <p>I am struggling with migrating an init script to systemd, on Debian Jessie.</p>
  
  <p>The goal is to access an URL after booting and before shutdown. The service file looks as follows:</p>
  
  <pre><code>[Unit]
  Description=some_name
  After=syslog.target network-online.target 
  Wants=network-online.target 
  
  [Service]
  Type=oneshot
  ExecStart=/bin/bash /home/xyz/scripts/register.bash
  ExecStop=/bin/bash /home/xyz/scripts/deregister.bash
  RemainAfterExit=yes
  
  [Install]
  WantedBy=multi-user.target 
  </code></pre>
  
  <p>The register script (URLs replaced by xyz, echos for debugging):</p>
  
  <pre><code>#!/bin/bash
  IP=$(hostname -I)
  IP=${IP/ /}
  
  echo  "-- register $(date) IP=$IP"  &gt;&gt;/home/xyz/register.txt
  echo  "   $(who -r) ID=$(id) HOST=$(host x.y.z)" &gt;&gt;/home/xyz/register.txt
  
  /usr/bin/curl --max-time 30 "http://x.y.z/some_script" -s -o /dev/null 
  
  echo "   exit code $?" &gt;&gt;/home/xyz/register.txt
  
  echo "-- reg done $(date)" &gt;&gt;/home/xyz/register.txt
  
  exit 0
  </code></pre>
  
  <p>Triggering the scripts from the command line works as expected, also as root. In particular, curl accesses the URL as it should.</p>
  
  <p>Also, the script is started upon booting and shutdown and leads the corresponding traces in register.txt. So far so good.</p>
  
  <p>What does not work, however, is that curl exits with code 28 (timeout) when started via systemd. This also happens when I trigger it with "systemd start " from a fully booted system with network up and running. So the unavailability of the network seems not to be the reason for the timeout.</p>
  
  <p>Why does curl timeout under these conditions, and what do I need to change to get the service running as intended?</p>
  
  <p>Thanks for your help</p>