title: Calling to restart a "service" in Linux from Python script not working from within crontab entry
body: <p>I have the following python test script (extracted from a much bigger .py file) which I'm trying to get working on an EC2 instance (haproxy OpsWorks instance).</p>
  
  <p>There seems to be a major difference between the permissions applied when running as a cron entry versus running as a python script from the shell.</p>
  
  <p>The closest I've found in any other posts is <a href="https://stackoverflow.com/questions/6124699/restart-service-crontab-problem">here</a> but that's relating to shell scripts and, given that I'm running python OK, the paths should ( I hope ) be sufficiently configured for the cronjob.</p>
  
  <p>Environment:
    - Python version: 2.6.8
    - Environment: OpsWorks HAProxy instance, on EC2.
    - Running as user: root.</p>
  
  <p>Script</p>
  
  <pre><code>import subprocess
  import boto
  import logging
  
  if __name__ == '__main__':
      logging.getLogger().setLevel(boto.logging.INFO)
      command = ['service', 'haproxy', 'reload'];
      logging.info('Executing: %s' % command)
      #shell=FALSE for sudo to work.
      subprocess.call(command, shell=False)
  </code></pre>
  
  <p>I have alternatively tried calling the subprocess command using the following to no avail.</p>
  
  <pre><code># subprocess.call("%s %s %s %s" % ('sudo', 'service', 'haproxy', 'reload'))
  </code></pre>
  
  <p>Output when run from the command line:</p>
  
  <pre><code>[root@lb1 ~]# python tester.py
  INFO:root:Executing: ['service', 'haproxy', 'reload']
  Reloading haproxy:
  [root@lb1 ~]#
  </code></pre>
  
  <p>Crontab entry:</p>
  
  <pre><code>[root@lb1 ~]# crontab -l
  */1 * * * * python ~/tester.py &gt; ~/testlog 2&gt;&amp;1
  </code></pre>
  
  <p>Output when run as a crontab command</p>
  
  <pre><code>[root@lb1 ~]# cat testlog
  INFO:root:Executing: ['service', 'haproxy', 'reload']
  Traceback (most recent call last):
    File "/root/tester.py", line 13, in &lt;module&gt;
      subprocess.call(command, shell=False)
    File "/usr/lib64/python2.6/subprocess.py", line 478, in call
      p = Popen(*popenargs, **kwargs)
    File "/usr/lib64/python2.6/subprocess.py", line 639, in __init__
      errread, errwrite)
    File "/usr/lib64/python2.6/subprocess.py", line 1228, in _execute_child
      raise child_exception
  OSError: [Errno 2] No such file or directory
  </code></pre>
  
  <p>I'm confused as to why on earth it's throwing the "No Such File Or Directory" error!</p>
  
  <p>Can anyone provide any pointers?  Incidentally this is part of a much bigger EC2 integration piece - hence the boto import [it's a nice way to get logging in this instance].  It's running as root because, from browsing SO, it's bad practice to have a cron entry for a user account running with a sudo command.</p>
  
  <p>Cheers,</p>