title: Run Python script in the background as a service
body: <p>i want to run python script as a service. for that i followed instructions <a href="http://blog.scphillips.com/posts/2013/07/getting-a-python-script-to-run-in-the-background-as-a-service-on-boot/" rel="nofollow">here</a>. </p>
  
  <p>for init script(myservice.sh), i copied as it is. </p>
  
  <p>for myservice.py ,</p>
  
  <pre><code>import sys, struct
  from socket import *
  
  SIZE = 1024      # packet size
  
  hostName = gethostbyname('0.0.0.0')
  
  mySocket  = socket( AF_INET, SOCK_DGRAM )
  mySocket.bind((hostName,18736))
  
  repeat = True
  while repeat:
     (data,addr) = mySocket.recvfrom(SIZE)
     data = struct.unpack('d',data)
     data=int(data[0])
  
     file = open("output.txt", "w")
     file.write(str(data))
     file.close()
  </code></pre>
  
  <p>When i start service "sudo /etc/init.d/myservice.sh start". 
  it successfully started. </p>
  
  <p>when i send udp data, but nothing is happend to "output.txt". what is the problem here?</p>