【问题标题】:How to stop Node.js application using forever module on Windows?如何在 Windows 上使用永久模块停止 Node.js 应用程序?
【发布时间】:2013-01-28 06:49:57
【问题描述】:

关于nodejs APP的forever模块,我经历了很多问题,但没有找到答案。

Forever 模块在 Linux 机器上运行良好,但现在我将我的应用程序放在 Windows 7 上并尝试永远运行它。 首先我安装了forever模块

npm install forever -g

之后我运行我的应用程序

forever start app.js

通过说文件 app.js 一直在运行并且我正在成功访问我的应用程序,它运行良好。

当我执行命令 forever stop app.js 时出现错误

没有永久文件正在运行

如果有人永远在 Windows 上使用,请建议我如何在 Windows 上停止我的应用程序。

【问题讨论】:

  • 我建议将您的 Node.js 应用程序作为服务运行。查看nssm.cc。也有用于此目的的 NPM 包。
  • 试试forever stopall命令,可能会起作用

标签: javascript node.js dom-events


【解决方案1】:

使用forever list 然后永远停止 id,例如forever stop 0

这是一个示例输出

user@some-server]$ forever list
info:    Forever processes running
data:        uid  command                                                  script forever pid   id logfile                          uptime        
data:    [0] 9Xzw ng serve --host 0.0.0.0 --port 4009         13164   29579    /home/ec2-user/.forever/9Xzw.log 7:1:20:50.412 
data:    [1] wOj1 npm run-script app-start-dev                                    29500   24978    /home/ec2-user/.forever/wOj1.log 0:0:5:3.433

这里的0 就像一个索引,位于输出的第一列。如果有两个进程在运行,我们可以使用0或1之类的索引来停止第一个或第二个进程。

forever stop 0 或 forever stop 1

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,发现这是因为我一直在运行 sudo(在 Linux 上),这样我就可以在端口 80 上运行生产站点。这成功了:

    sudo forever list
    

    【讨论】:

      【解决方案3】:

      这只是为了扩展@laktak 的答案。 forever list 在 Windows 上的结果如下所示:

      info:    Forever processes running
      data:        uid  command              script                          forever p
      id   id logfile                               uptime
      data:    [0] an1b "C:\nodejs\node.exe" C:\sbSerialWidget\server.js 8780    1
      0152    C:\Users\username\.forever\an1b.log STOPPED
      

      最初我不确定哪个是 ID,但我发现它是上面第二个 data 字段之后的第一个条目,因此您感兴趣的行是 ID 加粗和斜体:

      数据:[0] an1b C:\nodejs\node.exe C:\sbSerialWidget\server.js 8780 1 0152 C:\Users\username.forever\an1b.log 已停止

      所以要停止这个特定的实例,你需要运行:

      forever stop 0

      希望这可以帮助像我一样困惑的其他人

      【讨论】:

      • 是的,这令人困惑。文档说您可以通过 id、pid、脚本停止,但似乎只有 [0] 有效
      【解决方案4】:

      这是 Windows https://github.com/nodejitsu/forever/issues/337 中的一个错误 如果您需要停止您的应用程序,只需打开任务管理器并找到 node.js 进程并将其杀死。努力但工作。

      【讨论】:

      • 您也可以从命令行中杀死所有 Node 进程:taskkill /f /im node.exe 这将立即杀死所有正在运行的 Node 实例。
      【解决方案5】:

      你可以关注forever文档里面有forever相关的所有命令。

      Forever

       $ forever --help
            usage: forever [action] [options] SCRIPT [script-options]
          
            Monitors the script specified in the current process or as a daemon
          
            actions:
              start               Start SCRIPT as a daemon
              stop                Stop the daemon SCRIPT by Id|Uid|Pid|Index|Script
              stopall             Stop all running forever scripts
              restart             Restart the daemon SCRIPT
              restartall          Restart all running forever scripts
              list                List all running forever scripts
              config              Lists all forever user configuration
              set <key> <val>     Sets the specified forever config <key>
              clear <key>         Clears the specified forever config <key>
              logs                Lists log files for all forever processes
              logs <script|index> Tails the logs for <script|index>
              columns add <col>   Adds the specified column to the output in `forever list`. Supported columns: 'uid', 'command', 'script', 'forever', 'pid', 'id', 'logfile', 'uptime'
              columns rm <col>    Removed the specified column from the output in `forever list`
              columns set <cols>  Set all columns for the output in `forever list`
              cleanlogs           [CAREFUL] Deletes all historical forever log files
      
        options:
          -m  MAX          Only run the specified script MAX times
          -l  LOGFILE      Logs the forever output to LOGFILE
          -o  OUTFILE      Logs stdout from child script to OUTFILE
          -e  ERRFILE      Logs stderr from child script to ERRFILE
          -p  PATH         Base path for all forever related files (pid files, etc.)
          -c  COMMAND      COMMAND to execute (defaults to node)
          -a, --append     Append logs
          -f, --fifo       Stream logs to stdout
          -n, --number     Number of log lines to print
          --pidFile        The pid file
          --uid            DEPRECATED. Process uid, useful as a namespace for processes (must wrap in a string)
                           e.g. forever start --uid "production" app.js
                               forever stop production
          --id             DEPRECATED. Process id, similar to uid, useful as a namespace for processes (must wrap in a string)
                           e.g. forever start --id "test" app.js
                               forever stop test
          --sourceDir      The source directory for which SCRIPT is relative to
          --workingDir     The working directory in which SCRIPT will execute
          --minUptime      Minimum uptime (millis) for a script to not be considered "spinning"
          --spinSleepTime  Time to wait (millis) between launches of a spinning script.
          --colors         --no-colors will disable output coloring
          --plain          Disable command line colors
          -d, --debug      Forces forever to log debug output
          -v, --verbose    Turns on the verbose messages from Forever
          -s, --silent     Run the child script silencing stdout and stderr
          -w, --watch      Watch for file changes
          --watchDirectory Top-level directory to watch from
          --watchIgnore    To ignore pattern when watch is enabled (multiple option is allowed)
          -t, --killTree   Kills the entire child process tree on `stop`
          --killSignal     Support exit signal customization (default is SIGKILL),
                           used for restarting script gracefully e.g. --killSignal=SIGTERM
                           Any console output generated after calling `forever stop/stopall` will not appear in the logs
          -h, --help       You're staring at it
      
        [Long Running Process]
          The forever process will continue to run outputting log messages to the console.
          ex. forever -o out.log -e err.log my-script.js
      
        [Daemon]
          The forever process will run as a daemon which will make the target process start
          in the background. This is extremely useful for remote starting simple node.js scripts
          without using nohup. It is recommended to run start with -o -l, & -e.
          ex. forever start -l forever.log -o out.log -e err.log my-daemon.js
              forever stop my-daemon.js
      

      【讨论】:

        【解决方案6】:

        永远停止0

        其中 0 是您的应用程序运行的索引,如果您只有一个,则为 0。

        【讨论】:

          猜你喜欢
          • 2012-09-23
          • 1970-01-01
          • 2021-03-08
          • 2013-12-24
          • 1970-01-01
          • 1970-01-01
          • 2011-07-01
          • 1970-01-01
          相关资源
          最近更新 更多