title: restart systemd service if network connection is down
body: <p>I have this unit file running as a systemd service. It basically launches a Nodejs Express application running on a Raspberry Pi on local network. The application runs fine but if for some reason the router or network gets down and back up again, the app stops listening and I have to restart the systemd service to get it working again. </p>
  
  <pre><code>[Unit]
  Description=Employee Manager PiClock VueJs App
  Wants=network-online.target
  After=network-online.target
  
  [Service]
  ExecStart=/home/pi/.nvm/versions/node/v8.9.4/bin/node /home/pi/employee-manager-app/vuejs-app-server/app.js
  User=pi
  Restart=always
  # Restart service after 2 seconds if node service crashes
  RestartSec=2
  
  [Install]
  WantedBy=multi-user.target
  </code></pre>
  
  <p>Is there a way to restart the service automatically if the network gets down and up again? </p>