chore(examples): zero-downtime pm2 typescript example (#4907)

This commit is contained in:
Dmytro 2019-02-01 15:07:55 +02:00 committed by Pooya Parsa
parent 47898fbdac
commit 1fb9af33a3
7 changed files with 97 additions and 0 deletions

View File

@ -0,0 +1,26 @@
# PM2 with nuxt-ts example
[Gracefull zero-downtime restart](https://pm2.io/doc/en/runtime/best-practices/graceful-shutdown/#graceful-start)
`ecosystem.config.js` - configuration file for pm2
`listen_timeout` option depends on your need
## Zero-downtime deployment
*all depends on your deployment method. It's just example
#### Directories:
- `$PROJECT_ROOT` - your project root path on server
- `/current` - root dir for nginx(if you are using [proxy configuration](https://nuxtjs.org/faq/nginx-proxy/))
- `/_tmp` - Temporary dir to install and build project
- `/_old` - Previous build. Can be useful for fast reverting
#### Steps:
- deploy project to $PROJECT_ROOT/_tmp
- `cd $PROJECT_ROOT/_tmp`
- `npm i`
- `nuxt build` or if you are using TypeScript `nuxt-ts build`
- `mv $PROJECT_ROOT/current $PROJECT_ROOT/_old`
- `mv $PROJECT_ROOT/_tmp $PROJECT_ROOT/current`
- `cd $PROJECT_PATH/current`
- `pm2 startOrReload ecosystem.config.js`

View File

@ -0,0 +1,13 @@
module.exports = {
apps: [
{
name: 'pm2-nuxt-ts',
script: './node_modules/.bin/nuxt-ts',
args: 'start',
instances: 2,
exec_mode: 'cluster',
wait_ready: true,
listen_timeout: 5000
}
]
}

View File

@ -0,0 +1,9 @@
export default {
hooks: {
listen () {
if (process.send) {
process.send('ready')
}
}
}
}

View File

@ -0,0 +1,18 @@
{
"version": "1.0.0",
"private": true,
"dependencies": {
"nuxt-ts": "latest",
"vue-property-decorator": "^7.3.0"
},
"scripts": {
"dev": "nuxt-ts",
"build": "nuxt-ts build",
"start": "nuxt-ts start",
"generate": "nuxt-ts generate",
"lint": "tslint --project ."
},
"devDependencies": {
"tslint-config-standard": "^8.0.1"
}
}

View File

@ -0,0 +1,12 @@
<template>
<h1>
Hello world !
</h1>
</template>
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
@Component
export default class Home extends Vue {}
</script>

View File

@ -0,0 +1,10 @@
{
"extends": "@nuxt/typescript",
"compilerOptions": {
"baseUrl": ".",
"types": [
"@types/node",
"@nuxt/vue-app"
]
}
}

View File

@ -0,0 +1,9 @@
{
"defaultSeverity": "error",
"extends": [
"tslint-config-standard"
],
"rules": {
"prefer-const": true
}
}