Start server via PM2

This manual describes the sequence of actions to start server via the process manager PM2.

Install process manager PM2

Install process manager PM2 on the host with the deployed SAYMON platform using the following command:

$sudo npm install -g pm2

Configuration of actors

For all of the actors in-memory mode should be set in the file /etc/saymon/actors.json. For instance:

"RestServerWorkerActor": {
    "mode": "in-memory",
    "onCrash": "respawn"
  }

Disabling the server

In the case if the server has been started on the host as a service, it is necessary to stop and disable the service saymon-server.

Command to stop the service:

sudo service saymon-server stop

Systemctl command to disable the service:

sudo systemctl disable saymon-server

Init command to disable the service:

rm /etc/init/{saymon-server.conf,saymon-server-binary.conf}

Start the server via PM2

To start the server via PM2, it is necessary to execute the following command:

sudo -Hu saymon pm2 start /usr/local/saymon/server/ecosystem.config.js

In order to set automatic startup of the services when the OS is booted, execute the command:

sudo -Hu saymon pm2 startup

Setting up logs

Logs for each actor are recorded to the folder /home/saymon/.pm2/logs.

In order to set up log rotation, create the configuration file /etc/logrotate.d/pm2-saymon and add the following lines to it:

/home/saymon/.pm2/pm2.log /home/saymon/.pm2/logs/*.log {
  maxsize 100M
  daily
  missingok
  rotate 3
  compress
  notifempty
  copytruncate
}

The following command cleans all log files:

sudo -Hu saymon pm2 flush

Work with actors

To check statuses of the actors, execute the command:

sudo -Hu saymon pm2 status

Monitoring of work of the actors in real-time mode:

sudo -Hu saymon pm2 monit

In order to stop/start/restart a set of specific actors or all of the actors it i necessary to use the following commands, respectively:

sudo -Hu saymon pm2 start 4 5 | start actors under the numbers 4 and 5
sudo -Hu saymon pm2 restart 4 5 | restart actors under the numbers 4 and 5
sudo -Hu saymon pm2 stop 4 5 | stop actors under the numbers 4 and 5

sudo -Hu saymon pm2 start all | start all of the actors
sudo -Hu saymon pm2 restart all | restart all of the actors
sudo -Hu saymon pm2 stop all | stop all of the actors

In order to scale the number of actors, execute the command:

sudo -Hu saymon pm2 scale saymon-rest-server 4

where:

  • saymon-rest-server is the name of the actor,

  • 4 is the necessary amount of actors.

Restarting the server is not required.