最近又有种造轮子的冲动,于是打算写一个 Web Server,用来在服务器上管理自己的小项目们。
需求如下:
- GitHub 自动化部署
- 初始化及运行
- 自动注册 Webhook
- 进程管理
- 守护进程
- 数据监控
- 多核
- 热重启
- 文件监听
- Virtual Hosts
- Automatic HTTPS
- HTTP/2 & SPDY
具体地说,就是希望创建一份类似下面的配置文件:
|
|
然后服务器就会
- 下载运行所有项目;
- 注册监听 GitHub Webhooks;
- 在 Let’s Encrypt 注册 SSL 证书;
- 开启 HTTP/2 服务器,将流量按域名转发给各个项目;
- 监控项目运行情况,在报错或资源占用超标时重启。
目前已经基本实现现有需求,未来看情况还可能会支持 NVM 和 Travis CI。
项目地址: https://github.com/imsun/easy-pm
from https://imsun.net/posts/easy-pm-features
---------------------------------------
easy-pm
A simple and easy-to-use web server for managing Node.js projects.
Features
- Automatic HTTPS
- HTTP/2 & SPDY
- WebSockets
- Easy Deployment from GitHub
- Process Managing
- Virtual Hosts
- Gzip
- Static Server
Installation
$ npm install easy-pm -g
Usage
Just create a configuration file on your server and easy-pm start it.
$ easy-pm start config.json
Basic example:
{
"root": "/var/www",
"ssl": {
"sites": {
"example.com": "auto",
"www.example.com": "auto"
}
},
"webhook": {
"host": "your server address",
"token": "your github token"
},
"apps": [
{
"name": "example",
"domains": ["example.com", "www.example.com"],
"repository": "git@github.com:your_github_id/example.git",
"max_memory_restart": "100M"
},
{
"name": "static-example",
"domains": ["static-example.com"],
"repository": "git@github.com:your_github_id/example.git",
"branch": "gh-pages"
}
]
}
Configuration File
- root - string The directory to put your applications.
- port - number optional. The port easy-pm running on. Default
80
. - gzip - boolean optional. Whether enable gzip for all applications. Default
true
. - ssl - object optional.
- port - number optional. The SSL port easy-pm running on. Default
443
. - disable_redirect - boolean optional. Disable redirecting
http
requests tohttps
for all sites. Defaultfalse
. - sites - object.
- [domain] - object | "auto" If
"auto"
, easy-pm will install and manage SSL certificate from Let's Encryptautomatically.- key - string The path of private key.
- cert - string The path of certificate.
- disable_redirect - boolean optional. Disable redirecting
http
requests tohttps
. Defaultfalse
.
- [domain] - object | "auto" If
- port - number optional. The SSL port easy-pm running on. Default
- webhook - object optional.
- host - string Address of your server.
- token - string GitHub token to access GitHub API.
- apps - [object] check out Application Configuration for available attributes.
Application Configuration
Common
- type - string optional. Can be "node", "static" or "custom". Default
"node"
. - name - string Application name.
- port - number optional. The port used by your application is passed as
env.PORT
. Default is a random free port. - gzip - boolean optional. Whether enable gzip for this application. Default
true
. - domains - [string] optional. Domains to access this application.
- repository - string Git address of this application.
- branch - string Branch to work on. Default
"master"
. - max_memory_restart - string optional. Maximum memory over which the application will be restarted, ends with "K", "M" or "G".
- env - object optional. Environment variables for this application.
Node
In node mode, easy-pm will use
npm start
to your application.Static
In static mode, easy-pm will run a static server to serve your application.
- root - string optional. Root path for the static server. Default
"./"
. - 404 - string optional. The file to return when resource not found with status 404. Default
"404.html"
. - fallback - string optional. Similar to
404
, but returns status 200. Used for some single page applications.
Custom
In custom mode, you can run other non-Node.js project and custom your scripts.
- script - string Path of file to execute.
- args - [string] optional. Arguments to pass to the script.
- interpreter - string The interpreter to execute the script.
- interpreterArgs - [string] optional. Arguments to pass to the interpreter.
CLI
$ easy-pm -h
Usage: easy-pm [options] [command]
Commands:
start <file> start service with config file
stop <file> stop service with config file
list list running applications
Options:
-h, --help output usage information
-V, --version output the version number
from https://github.com/imsun/easy-pm
No comments:
Post a Comment