0

My project is hosted on Webfaction and supervisor is used to be aware of processes. I use shell utils to get the PID of supervisor and it works just fine when I do it manually, but I got random PIDs when executing the same command remotely with Fabric

Code to get PID of supervisor

spid = run('ps auxw | grep supervisord | grep %s | tr -s \' \' | cut -d\  -f 2' % USER)

if spid:                   # if supervisor is running and PID is found
    run('kill %s' % spid)  # kill supervidor daemon

I'm confused why I get random PIDs when calling command remotely, what is wrong with the way I do it?

Thanks,

Sultan

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
sultan
  • 5,978
  • 14
  • 59
  • 103
  • What does a "random" pid look like? Could it be the PID of a process that was killed? – nneonneo Sep 23 '12 at 08:47
  • The above command returns None if supervisor is not running, so I my case when executing command remotely with Fabric I've wrong PIDs though if I check manually the same command I got correct PID – sultan Sep 23 '12 at 09:20

1 Answers1

0

You could solve this simpler by using pkill or pgrep to find the pid. But also if that's all you're doing I'd say use the -j|--pidfile= option so you don't have to look it up through the process output.

Morgan
  • 4,143
  • 27
  • 35
  • Thank you @Morgan. By the way I used command like `ps -u imanhodjaev -o rss,etime,pid,command` to figure out PIDs – sultan Sep 24 '12 at 13:09