#!/usr/bin/env python

import sys
from os import system

class NginxCtl(object):
  """
  Nginx control operations abstraction
  """

  def __init__(self,
               pid_file_path = "logs/nginx.pid",
               bin_file_path = "sbin/nginx"):
    """
    Arguments:
    
    pid_file_path: Nginx pid file path
    bin_file_path: Nginx bin file path
    """
    self._pid_file_path = pid_file_path
    self._bin_file_path = bin_file_path
    
  def run(self, command):
    """
    Runs the command
    """
    cmd2run = ""
    
    if command == "start":
      cmd2run = "sudo %s" % self._bin_file_path
    elif command == "restart":
      cmd2run = self.signal_command("HUP")
    elif command == "stop":
      cmd2run = self.signal_command("QUIT")
    elif command == "force-stop":
      cmd2run = self.signal_command("INT")
    elif command == "reopen-log":
      cmd2run = self.signal_command("USR1")
    elif command == "upgrade-executable":
      cmd2run = self.signal_command("USR2")
    elif command == None:
      self.quit("Commands are start, restart, stop, force-stop, reopen-log, upgrade-executable")
    else:
      self.quit("Unknown command %s" % command)
    
    print "Executing %s" % cmd2run
    system(cmd2run)

  def quit(self, message):
     """
     Prints a message and exits
     """
     print(message)
     sys.exit()

  def signal_command(self, signal):
     """
     Returns shell command used to send some signal
     to Nginx master process.
     """
     return "sudo kill -s %s %s" % (signal, self.find_pid())

  def find_pid(self):
    """
    Returns Nginx pid
    """
    pidfile = open(self._pid_file_path)
    pid     = pidfile.read().strip()
    pidfile.close()

    return pid


ctl = NginxCtl(pid_file_path = "/usr/local/nginx/logs/nginx.pid",
               bin_file_path = "/usr/local/nginx/sbin/nginx")

try:
  command = sys.argv[1]
except:
  command = None

ctl.run(command) 

@@ -624,21 +624,20 @@
 d == %22re
-start
+load
 %22:%0A     
@@ -1052,21 +1052,20 @@
 tart, re
-start
+load
 , stop, 

Rename restart command to reload because this is what Nginx really does.