如果你有 PHP 开发经验,会习惯在修改 PHP 脚本后直接刷新浏览器以观察结果,而你 在开发 Node.js 实现的 HTTP 应用时会发现,无论你修改了代码的哪一部份,都必须终止 Node.js再重新运行才会奏效。这是因为 Node.js 只有在第一次引用到某部份时才会去解析脚 本文件,以后都会直接访问内存,避免重复载入,而 PHP 则总是重新读取并解析脚本(如 果没有专门的优化配置)。Node.js的这种设计虽然有利于提高性能,却不利于开发调试,因 为我们在开发过程中总是希望修改后立即看到效果,而不是每次都要终止进程并重启。
supervisor 可以帮助你实现这个功能,它会监视你对代码的改动,并自动重启 Node.js。 使用方法很简单,首先使用 npm 安装 supervisor:
$ npm install -g supervisor
如果你使用的是 Linux 或 Mac,直接键入上面的命令很可能会有权限错误。原因是 npm 需要把 supervisor 安装到系统目录,需要管理员授权,可以使用 sudo npm install -g supervisor 命令来安装。
接下来,使用 supervisor 命令启动 app.js: $ supervisor app.js
DEBUG: Running node-supervisor with DEBUG: program 'app.js' DEBUG: --watch '.' DEBUG: --extensions 'node|js' DEBUG: --exec 'node'
DEBUG: Starting child process with 'node app.js'
DEBUG: Watching directory '/home/byvoid/.' for changes. HTTP server is listening at port 3000.
当代码被改动时,运行的脚本会被终止,然后重新启动。在终端中显示的结果如下:
DEBUG: crashing child DEBUG: Starting child process with 'node app.js' HTTP server is listening at port 3000.
supervisor 这个小工具可以解决开发中的调试问题。
Supervisor是一个进程管理工具,官方的说法
用途就是有一个进程需要每时每刻不断的跑,但是这个进程又有可能由于各种原因有可能中断。当进程中断的时候我希望能自动重新启动它,此时,我就需要使用到了Supervisor
这个工具主要就两个命令:
supervisord : supervisor的服务器端部分,启动supervisor就是运行这个命令
supervisorctl:启动supervisor的命令行窗口。
安装(Centos):
- # yum install python-setuptools
- # easy_install supervisor
- 如果easy_install不好使就从官方下载:
- 然后通过python安装:
- # tar zxf supervisor-3.1.3.tar.gz
- # cd supervisor
- # python setup.py install
成功安装后可以登陆python控制台输入import supervisor 查看是否能成功加载。
生成配置文件(supervisord.conf):
echo_supervisord_conf > /etc/supervisord.conf
修改配置文件:
在supervisord.conf最后增加(分号后边的表示注释,可以不写):
- [program:bandwidth]
- command=python26 /usr/local/bin/bandwidth.sh ;需要执行的命令wd)
- user =root ;(default is current user , required if root)
- autostart=true ;start at supervisord start (default: true)
- autorestart=true ;whether/when to restart (default: unexpected)
- startsecs=3 ;number of secs prog must stay running ( def . 1)
- stderr_logfile=/tmp/bandwidth_err.log ;redirect proc stderr to stdout (default false) 错误输出重定向
- stdout_logfile=/tmp/bandwidth.log ;stdout log path, NONE for none; default AUTO, log输出
- (更多配置说明请参考:http://supervisord.org/configuration.html)
运行命令:
supervisord -c /etc/supervisord.conf //启动supervisor
supervisorctl //打开命令行
- [root @iZ2365j7l5bZ bin]# supervisorctl status
- bandwidth RUNNING pid 2423 , uptime 0 : 06 : 35
- [root @iZ2365j7l5bZ bin]# supervisorctl help
- default commands (type help <topic>):
- =====================================
- add clear fg open quit remove restart start stop update
- avail exit maintail pid reload reread shutdown status tail version
ctl中: help //查看命令
ctl中: status //查看状态
另外有一个坑需要注意:如果修改了 /etc/supervisord.conf ,需要执行 supervisorctl reload 来重新加载配置文件,否则不会生效。。。
+
+
+
=
+
=
+
相关推荐
supervisor gunicorn nodejs apache rsync mysql redis vuex vue-router axios element-ui ansible-playbook ansible fabric this project use python api process the data, with the separation of web page file;...
NodeJS和npm / yarn Python3.4 +和pip3 雷迪斯 :warning_selector: 请在根目录下运行以下命令 安装Job Supervisor和Redis git clone https://github.com/cybergis/job-supervisor.git cd job-supervisor npm ...
nginx + php + mysql + redis + rabbitmq + supervisor nodejs 环境 v1 进入目录,执行 docker-compose up 1、python.default, uWSGU服务启动 loalhost:8000 2、python.mysite,Django项目 loalhost 3、python.test...
三方的进程管理工具,如: python的supervisor或者nodejs的pm2 。每种方式都有一定的优劣,我们希望继承go语言部署集成的便捷易用思想,不需要再安装其他依赖软件,并增强进程管理工具的体验。和pm2不一样的是, ...
为了防止不同环境的配置文件混淆,可以在`.gitignore`文件中忽略除`default.js`之外的所有配置文件,避免将敏感信息推送到版本控制系统。 ``` # config config/! config/default.* ``` 确保在生产环境中的`...
xe-crawlerxe-crawler 是遵循声明式、可监测理念的分布式爬虫,其计划提供 Node.js、Go、Python 多种实现,能够对于静态 Web 页面、动态 Web 页面、关系型数据库、操作系统等异构多源数据进行抓取。xe-crawler 希望...