title: PID File issue with running a perl script as a daemon
body: <p>I've attempted to use the example given <a href="https://stackoverflow.com/questions/766397/how-can-i-run-a-perl-script-as-a-system-daemon-in-linux">here</a> for running a perl script as a daemon:</p>
  <p>However, when attempting to start the daemon I'm getting the following error:
  systemd<a href="https://stackoverflow.com/questions/766397/how-can-i-run-a-perl-script-as-a-system-daemon-in-linux">1</a>: myDaemon.service: Can't open PID file /run/myDaemon.pid (yet?) after start: Operation not permitted</p>
  <p>I've found several others who've had this issue, but none of the suggested fixes, such as changing the pid location from /var/run to /run, have worked for me.  Any suggestions?</p>
  <p>Here is the contents of /etc/init.d/myDaemon:</p>
  <pre><code>#!/bin/bash
  #
  # myDaemon This starts and stops myDaemon 
  #
  # chkconfig: 2345 12 88
  # description: myDaemon is a perl script that does stuff
  # processname: myDaemon
  # pidfile: /run/myDaemon.pid
  ### BEGIN INIT INFO
  # Provides: $myDaemon
  ### END INIT INFO
  
  # Source function library.
  . /lib/lsb/init-functions
  
  binary=&quot;/home/myuser/myDaemon.pl&quot;
  
  [ -x $binary ] || exit 0
  
  RETVAL=0
  
  start() {
      echo -n &quot;Starting myDaemon: &quot;
      daemon $binary
      RETVAL=$?
      PID=$!
      echo
      [ $RETVAL -eq 0 ] &amp;&amp; touch /var/lock/subsys/myDaemon
  
      echo $PID &gt; /run/myDaemon.pid
  }
  
  stop() {
      echo -n &quot;Shutting down myDaemon: &quot;
      killproc myDaemon
      RETVAL=$?
      echo
      if [ $RETVAL -eq 0 ]; then
          rm -f /var/lock/subsys/myDaemon
          rm -f /run/myDaemon.pid
      fi
  }
  
  restart() {
      echo -n &quot;Restarting myDaemon: &quot;
      stop
      sleep 2
      start
  }
  
  case &quot;$1&quot; in
      start)
          start
      ;;
      stop)
          stop
      ;;
      status)
          status myDaemon
      ;;
      restart)
          restart
      ;;
      *)
          echo &quot;Usage: $0 {start|stop|status|restart}&quot;
      ;;
  esac
  
  exit 0
  </code></pre>
  <p>And here are the relevant contents of the perl script under /home/myUser/myDaemon.pl:</p>
  <pre><code>    #! /usr/bin/perl
      use strict;
      use warnings;
      use Proc::Daemon;
      
      # Proc::Daemon
      Proc::Daemon::Init;
      my $continue = 1;
      $SIG{TERM} = sub { $continue = 0 };
  
  
  while($continue) {
    # does stuff
  }
  </code></pre>