【问题标题】:commands to stop & start nginx停止和启动 nginx 的命令
【发布时间】:2012-11-28 02:45:09
【问题描述】:

我正在开发 Rails v2.3.2 应用程序。在 Ubuntu 机器上。

现在,我想要两个 rake 任务分别 stopstart *Nginx*,这需要什么命令?

  task :start_nginx do
     puts "stop Nginx..."
     system '...' #What is the command to stop Nginx?
  end

  task :stop_nginx do
     puts "stop Nginx..."
     system '...' #What is the command to start Nginx?
  end

【问题讨论】:

    标签: ruby-on-rails ubuntu nginx


    【解决方案1】:

    如果你刚刚在 Ubuntu 上安装了常规的 nginx 包,你已经有了一个启动脚本,比如:

    /etc/init.d/nginx (start|stop)
    

    如果没有,请看into the documentation

    以 root 身份运行 /usr/local/nginx/sbin/nginx 来启动服务器。

    你通过执行来停止服务器

    kill `cat /var/run/nginx.pid`
    

    【讨论】:

      【解决方案2】:

      在 Ubuntu 中正确的做法是使用 service 而不是 init.d

      sudo service nginx stop
      sudo service nginx start
      sudo service nginx restart
      

      Explanation on the difference

      【讨论】:

        【解决方案3】:

        这取决于系统。

        如果您使用的是新贵,命令将是:

        start nginx
        stop nginx
        

        否则它可能是以下之一:

        /etc/init.d/nginx start
        /etc/init.d/nginx stop
        
        /etc/rc.d/nginx start
        /etc/rc.d/nginx stop
        

        甚至可能:

        nginx
        killall -9 nginx
        

        【讨论】:

        • 为什么你有两个起点和终点?他们都需要运行吗?或者任何一个都可以?
        • 哪一个取决于你的系统,例如debian使用/etc/init.d,但是arch使用/etc/rc.d
        【解决方案4】:

        在 debian/ubuntu 上

        /etc/init.d/nginx (start|stop|reload)
        

        在 centOS/RHEL 上

        service nginx (start|stop|reload)
        

        您必须以 root 身份登录。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-03-31
          • 1970-01-01
          • 1970-01-01
          • 2015-05-01
          • 2012-04-11
          • 1970-01-01
          相关资源
          最近更新 更多