title: Socat and systemd
body: <p>I need to run a script, which among many things running socat. 
  Running the script from the command line works fine, now what I want is that this script is run as a service. </p>
  
  <p>This is the script I have: </p>
  
  <pre><code>#!/usr/bin/env sh
  
  set -e
  
  TTY=${AQM_TTY:-/dev/ttyUSB0}
  
  /reg_sesion/create
  DESTINOS=(http://127.0.0.1)
  
  LOG_DIR=./logs-aqm
  
  mkdir -p "${LOG_DIR}"
  
  ###ADDED####
  
  echo $$ &gt; /var/run/colector.pid
  
  socat -b 115200 ${TTY},echo=0,crnl - |
  
  grep --line-buffered "^rs" |
  while read post; do
  for destino in ${DESTINOS[@]}; do
  wget --post-data="$(echo "${post}" | tr -d "\n")" \
  -O /dev/null \
  --no-verbose \
  --background \
  --append-output="${LOG_DIR}/${destino//\/}.log" \
  "${destino}/reg_sesion/create"
  done
  
  echo "${post}" | tee -a "${LOG_DIR}/aqm.log"
  done
  </code></pre>
  
  <p>And the service file:</p>
  
  <pre><code>[Unit]
  Description=colector
  
  [Service]
  Type=simple
  PIDFile=/var/run/colector.pid
  
  User=root
  Group=root
  
  #ExecStart=/root/socat.sh
  ExecStart=/bin/sh -c '/root/socat.sh'
  
  [Install]
  WantedBy=multi-user.target 
  </code></pre>
  
  <p>When I start the service, the process starts and ends quickly. </p>
  
  <p>any ideas? </p>
  
  <p>Thanks for your time</p>