5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

pm2 を Systemd で動かす

Last updated at Posted at 2021-03-12

Ubuntu 20.10 で確認しました。

次のようにして、pm2 を動かせるようにします。

起動

sudo systemctl status pm2-uchida.service


停止

>```bash
sudo systemctl stop pm2-uchida.service

モニター

sudo systemctl status pm2-uchida.service


/etc/systemd/system/pm2-uchida.service の作成方法

次のようになっている状態で、

```text
$ pm2 list
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name               │ mode     │ ↺    │ status    │ cpu      │ memory   │
├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
│ 0  │ ee01               │ fork     │ 0    │ online    │ 0%       │ 85.1mb   │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘
$ pm2 save
[PM2] Saving current process list...
[PM2] Successfully saved in /home/uchida/.pm2/dump.pm2
pm2 save
$ pm2 delete 0
[PM2] Applying action deleteProcessId on app [0](ids: [ '0' ])
[PM2] [ee01](0) ✓
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name               │ mode     │ ↺    │ status    │ cpu      │ memory   │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘
Current process list running is not in sync with saved list. App ee01 differs. Type 'pm2 save' to synchronize.
$ pm2 startup
[PM2] Init System found: systemd
[PM2] To setup the Startup Script, copy/paste the following command:
sudo env PATH=$PATH:/usr/local/bin /usr/local/lib/node_modules/pm2/bin/pm2 startup systemd -u uchida --hp /home/uchida

画面に出てきたコマンドを実行

sudo env PATH=$PATH:/usr/local/bin /usr/local/lib/node_modules/pm2/bin/pm2 startup systemd -u uchida --hp /home/uchida

/etc/systemd/system/pm2-uchida.service
が作成されます。

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?