GitBook:启动多实例进程失败:listen EADDRINUSE :::35729
1.报错
目录结构:
/home/test1280 tree $HOME -L 2
/home/test1280
├── book1
│ ├── README.md
│ └── SUMMARY.md
└── book2
├── README.md
└── SUMMARY.md
2 directories, 4 files
在一个主机中启动多个gitbook进程提供服务。
第一个gitbook实例监听4000,启动正常:
/home/test1280 cd book1 && gitbook serve --port=4000
Live reload server started on port: 35729
Press CTRL+C to quit ...
info: 7 plugins are installed
info: loading plugin "livereload"... OK
info: loading plugin "highlight"... OK
info: loading plugin "search"... OK
info: loading plugin "lunr"... OK
info: loading plugin "sharing"... OK
info: loading plugin "fontsettings"... OK
info: loading plugin "theme-default"... OK
info: found 1 pages
info: found 0 asset files
info: >> generation finished with success in 0.7s !
Starting server ...
Serving book on http://localhost:4000
第二个gitbook实例监听4001,启动异常:
/home/test1280 cd book2 && gitbook serve --port=4001
... Uhoh. Got error listen EADDRINUSE :::35729 ...
Error: listen EADDRINUSE :::35729
at Object.exports._errnoException (util.js:1020:11)
at exports._exceptionWithHostPort (util.js:1043:20)
at Server._listen2 (net.js:1271:14)
at listen (net.js:1307:10)
at Server.listen (net.js:1403:5)
at Server.listen (/home/test1280/.gitbook/versions/3.2.3/node_modules/tiny-lr/lib/server.js:164:15)
at Promise.apply (/home/test1280/.gitbook/versions/3.2.3/node_modules/q/q.js:1165:26)
at Promise.promise.promiseDispatch (/home/test1280/.gitbook/versions/3.2.3/node_modules/q/q.js:788:41)
at /home/test1280/.gitbook/versions/3.2.3/node_modules/q/q.js:1391:14
at runSingle (/home/test1280/.gitbook/versions/3.2.3/node_modules/q/q.js:137:13)
You already have a server listening on 35729
You should stop it and try again.
2.版本
/home/test1280 node -v
v6.17.1
/home/test1280 npm -v
3.10.10
/home/test1280 gitbook -V
CLI version: 2.3.2
GitBook version: 3.2.3
3.解决
根据报错提示:Error: listen EADDRINUSE :::35729
可见是端口占用(35729)导致第二个gitbook进程监听端口失败退出。
/home/test1280 netstat -lntp | grep 35729
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp6 0 0 :::35729 :::* LISTEN 19720/node
/home/test1280 ps aux | grep 19720
test1280 19720 1.6 0.4 1325856 137872 pts/11 Sl+ 13:48 0:04 node /bin/gitbook serve --port=4000
test1280 21332 0.0 0.0 112712 960 pts/9 S+ 13:53 0:00 grep --color=auto 19720
可见此端口占用(35729)是第一个gitbook进程监听占用。
即:gitbook一个进程要占用(至少)两个端口,35729、4000。
35729端口如同4000端口,gitbook命令行参数在启动时指定:lrport
/home/test1280 gitbook help
build [book] [output] build a book
--log Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)
--format Format to build to (Default is website; Values are website, json, ebook)
--[no-]timing Print timing debug information (Default is false)
serve [book] [output] serve the book as a website for testing
--port Port for server to listen on (Default is 4000)
--lrport Port for livereload server to listen on (Default is 35729)
--[no-]watch Enable file watcher and live reloading (Default is true)
--[no-]live Enable live reloading (Default is true)
--[no-]open Enable opening book in browser (Default is false)
--browser Specify browser for opening book (Default is )
--log Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)
--format Format to build to (Default is website; Values are website, json, ebook)
install [book] install all plugins dependencies
--log Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)
parse [book] parse and print debug information about a book
--log Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)
init [book] setup and create files for chapters
--log Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)
pdf [book] [output] build a book into an ebook file
--log Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)
epub [book] [output] build a book into an ebook file
--log Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)
mobi [book] [output] build a book into an ebook file
--log Minimum log level to display (Default is info; Values are debug, info, warn, error, disabled)
例如:
启动第一个gitbook实例:
/home/test1280 cd book1 && gitbook serve --port=4000 --lrport=4100
Live reload server started on port: 4100
Press CTRL+C to quit ...
info: 7 plugins are installed
info: loading plugin "livereload"... OK
info: loading plugin "highlight"... OK
info: loading plugin "search"... OK
info: loading plugin "lunr"... OK
info: loading plugin "sharing"... OK
info: loading plugin "fontsettings"... OK
info: loading plugin "theme-default"... OK
info: found 1 pages
info: found 0 asset files
info: >> generation finished with success in 1.3s !
Starting server ...
Serving book on http://localhost:4000
启动第二个gitbook实例:
/home/test1280 cd book2 && gitbook serve --port=4001 --lrport=4101
Live reload server started on port: 4101
Press CTRL+C to quit ...
info: 7 plugins are installed
info: loading plugin "livereload"... OK
info: loading plugin "highlight"... OK
info: loading plugin "search"... OK
info: loading plugin "lunr"... OK
info: loading plugin "sharing"... OK
info: loading plugin "fontsettings"... OK
info: loading plugin "theme-default"... OK
info: found 1 pages
info: found 0 asset files
info: >> generation finished with success in 0.7s !
Starting server ...
Serving book on http://localhost:4001
同主机启动多个gitbook实例,需要port、lrport各不占用、各不相同。
4.参考
https://programmersought.com/article/22155979603/
https://cloud.tencent.com/developer/article/1439336
https://blog.csdn.net/u012887259/article/details/102425734
http://gitbook.number10.cn/Chapter4/gitbook命令.html
https://huataihuang.gitbooks.io/cloud-atlas/content/develop/doc/gitbook/run_multi_gitbook_in_one_host.html