Skip to content

Commit

Permalink
chore(examples): zero-downtime pm2 typescript example (#4907)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschewchenko authored and pi0 committed Feb 1, 2019
1 parent 47898fb commit 1fb9af3
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 0 deletions.
26 changes: 26 additions & 0 deletions examples/pm2-typescript/README.md
Original file line number Diff line number Diff line change
@@ -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`
13 changes: 13 additions & 0 deletions examples/pm2-typescript/ecosystem.config.js
Original file line number Diff line number Diff line change
@@ -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
}
]
}
9 changes: 9 additions & 0 deletions examples/pm2-typescript/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default {
hooks: {
listen () {
if (process.send) {
process.send('ready')
}
}
}
}
18 changes: 18 additions & 0 deletions examples/pm2-typescript/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
12 changes: 12 additions & 0 deletions examples/pm2-typescript/pages/index.vue
Original file line number Diff line number Diff line change
@@ -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>
10 changes: 10 additions & 0 deletions examples/pm2-typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "@nuxt/typescript",
"compilerOptions": {
"baseUrl": ".",
"types": [
"@types/node",
"@nuxt/vue-app"
]
}
}
9 changes: 9 additions & 0 deletions examples/pm2-typescript/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"defaultSeverity": "error",
"extends": [
"tslint-config-standard"
],
"rules": {
"prefer-const": true
}
}

0 comments on commit 1fb9af3

Please sign in to comment.