Pierrot
pm2 virtual-host and deploy cli
Installation
$ npm install pm2 bouncy pierrot --global
Define pierrot.yml
Can use $ sudo pierrot vhost
if define one or more apps
in ./pierrot.yml
.
apps: homepage: repo: https://github.com/59naga/berabou.me.git from: 59naga.localhost to: 59798
Start the virtual host using 80 port.
$ sudo pierrot vhost#[PM2] Spawning PM2 daemon #[PM2] PM2 Successfully daemonized #process name not found #┌──────────┬────┬──────┬───────┬────────┬─────────┬────────┬─────────────┬──────────┐ #│ App name │ id │ mode │ pid │ status │ restart │ uptime │ memory │ watching │ #├──────────┼────┼──────┼───────┼────────┼─────────┼────────┼─────────────┼──────────┤ #│ VHOST │ 0 │ fork │ 85314 │ online │ 0 │ 0s │ 29.520 MB │ disabled │ #└──────────┴────┴──────┴───────┴────────┴─────────┴────────┴─────────────┴──────────┘ # #successfully `vhost`. # # Please fix: # # $ sudo chmod -R 777 ~/.pm2 # # See: https://github.com/Unitech/PM2/issues/837 #
$ sudo chmod -R 777 ~/.pm2
Deploy the app in local.
$ pierrot apps? apps homepage? task initialize? really Yes# apps: git clone https://github.com/59naga/berabou.me.git homepage # apps/homepage: npm install --production # apps/homepage: delete and start pm2 process # process name not found # # homepage was successfully the `initialize` # # ┌──────────┬────┬──────┬───────┬────────┬─────────┬────────┬─────────────┬──────────┐ # │ App name │ id │ mode │ pid │ status │ restart │ uptime │ memory │ watching │ # ├──────────┼────┼──────┼───────┼────────┼─────────┼────────┼─────────────┼──────────┤ # │ VHOST │ 0 │ fork │ 85314 │ online │ 0 │ 3m │ 29.520 MB │ disabled │ # │ homepage │ 1 │ fork │ 85830 │ online │ 0 │ 0s │ 34.074 MB │ disabled │ # └──────────┴────┴──────┴───────┴────────┴─────────┴────────┴─────────────┴──────────┘
Becomes...
$ tree# . # ├── node_modules # ├── package.json # ├── pierrot.yml # └── apps # └── homepage # ├── node_modules # ├── package.json # └── ...
And be available the http://59naga.localhost
if Add 127.0.0.1 59naga.localhost
to /etc/hosts
.
Pierrot tasks
Always set the production
to process.env.NODE_ENV
.
reload
- Pulling repositories in specified apps (eg
cd apps/name && git pull
). - Reload the processes. (eg
pm2 reload <apps...>
)
update
- Pulling repositories in specified apps (eg
cd apps/name && git pull
). - Install dependencies. (eg
npm install --production
) - Reload the processes. (eg
pm2 reload <apps...>
)
deleteAndStart
- Remove the processes. (eg
pm2 delete <apps...>
) - Start the processes using pierrot.yml^1. (eg
pm2 start <apps...>
)
initialize
- Delete the folder of apps if has
apps/repo
. (egrm -rf <apps/name>
) - Clone the
apps/repo
asapps/name
. (eggit clone apps/repoValue apps/name
) - Install dependencies. (eg
cd apps/name && npm install --production
) - Start the processes using
pierrot.yml
. (egpm2 start <apps...>
)
302 redirect
VHOST sends the Location header in the 302 if specify app/to
as string.
oldSite: from: oldsite.example.com to: renewal.example.com
pm2 reload VHOST# ... curl oldsite.example.com/foo/bar?baz --head# HTTP/1.1 302 Found # Location: http://renewal.example.com/foo/bar?baz # Date: Mon, 02 Nov 2015 03:36:34 GMT # Connection: keep-alive
https
Define key
and cert
fields to ./pierrot.yml
.
Becomes add the port 443(secure mode) at pierrot vhost
.
key: /path/to/private.keycert: /path/to/public.cert apps: homepage: repo: https://github.com/59naga/berabou.me.git from: 59naga.localhost to: 59798
$ sudo pierrot vhost$ pm2 logs VHOST# PIERROT_VHOST listening at http://localhost:80/ # PIERROT_VHOST listening at http://localhost:443/