Launching application via
egg-bin dev will bring something magical to help people to develop in high efficiency. However, actually, those features are not required in production or any other environment. Let's walk through and learn how to deploy your application in Egg's way.
There are two steps to achieve building once and deploying multiply from source code to runtime.
Generally, before deploying the application, dependencies will be installed with
--production, which will exclude
devDependencies because those used in development may increase the size of package released or even create pitfalls that you never expect.
$ cd baseDir
Both the application and dependencies will be packed into a tgz file, what you are going to do is unzipping and launching it.
Reusable package brings a few pros in:
- Environments in building and runtime are different, try to keep the later environment pure and stable.
- Abbreviating publish progress and making rollback without hassle.
>= 8.0.0) is required so that you should make sure it is pre-installed in runtime environment.
egg-cluster to create Master process, which you can rely on to secure the application instead of daemon manager like pm2. The API is also really convenient for developers to achieve that, just
And framework also provide egg-scripts for developers to start/stop application at prod mode.
Firstly, we need to import
$ npm i egg-scripts --save
npm scripts to
Then we are able to use
npm start and
npm stop to manage application.
egg-scriptshas limited support for Windows, see #22.
$ egg-scripts start --port=7001 --daemon --title=egg-server-showcase
--port=7001http server port, will use
process.env.PORT, default to
--daemonwhether run at background, so you don't need
nohup. Ignore this when the application run in docker instance.
--env=prodthen framework env, will use
process.env.EGG_SERVER_ENV, default to
--workers=2worker count, default to cpu cores, which can leverage the capability of the cpu.
ps + grep, default to
package.jsonor pass this args, when you are using Custom Framework.
--ignore-stderrignore the std err at start up。
- support all options from egg-cluster, such as
# Dispatch with arguments
Arguments of dispatch can be configured in
server.listen supports arguments including
hostname to change dispatching behavior. One thing you should know is that the
egg.startCluster will override the one in application config.
$ egg-scripts stop
This command will kill master process which will handler and notice worker and agent to gracefull exit.
Also you can manually call
ps -eo "pid,command" | grep -- "--title=egg-server" to find master process then