Linux service

Using systemd or supervisord, you can run and manage machbase-neo process as as system service, so that make it to start automatically when the system boot.

Create start/stop script

Create neo-start.sh

$ vi neo-start.sh
#!/bin/bash 
exec /data/machbase-neo serve --host 0.0.0.0 --log-filename /data/log/machbase-neo.log
$ chmod 755 neo-start.sh

Create neo-stop.sh

$ vi neo-stop.sh
#!/bin/bash 
/data/machbase-neo shell shutdown
$ chmod 755 neo-stop.sh

systemd

Create neo.service

$ cd /etc/systemd/system
$ sudo vi neo.service
[Unit]   
Description=neo service   
StartLimitBurst=10   
StartLimitIntervalSec=10   
  
[Service]   
User=machbase   
LimitNOFILE=65535   
ExecStart=/data/neo-start.sh
ExecStop=/data/neo-stop.sh
ExecStartPre=sleep 2   
WorkingDirectory=/data   
Restart=always   
RestartSec=1   
  
[Install]   
WantedBy=multi-user.target   
  • Modify the User and paths according to your environment.

Activate the service.

$ sudo chmod 755 neo.service
$ sudo systemctl daemon-reload

Make the service to auto-start when host machine re-boot.

$ sudo systemctl enable neo.service

Done

After activating the service, you can control it with the following commands:

$ sudo systemctl start neo.service
$ sudo systemctl status neo.service
$ sudo systemctl stop neo.service

supervisord

Create neo.conf

$ cd /etc/supervisor/conf.d
$ sudo vi neo.conf
[program:neo]
command=/data/neo-start.sh
priority=10   
autostart=true   
autorestart=true   
environment=HOME=/home/machbase   
stdout_logfile=/data/log/machbase-neo_stdout.log   
stderr_logfile=/data/log/machbase-neo_stderr.log   
user=machbase   
  • Modify the user and paths according to your environment.
  • In the above example, the log folder /data/log should exist in advance.

Update Supervisord

$ sudo supervisorctl reread
$ sudo supervisorctl update

Done

After activating the service, you can control machbase-neo with the following commands:

$ sudo supervisorctl start neo
$ sudo supervisorctl status neo
$ sudo supervisorctl stop neo

PM2

Create neo-start.sh

$ vi neo-start.sh
#!/bin/bash
exec /data/machbase-neo serve --host 0.0.0.0
  • Logs will be managed by PM2, so the --log-filename option is not necessary.

Executable neo-start.sh

$ chmod 755 neo-start.sh

Run machbase-neo using PM2.

$ pm2 start /data/neo-start.sh --name neo --log /data/log/machbase-neo.log

Check the status of machbase-neo.

$ pm2 status neo

Make PM2 to auto-start

  • You can skip this process if you have already executed it.

To automatically generate and configuration a startup script just type the command (without sudo) pm2 startup:

$ 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 machbase --hp /home/machbase

Then copy/paste the displayed command onto the terminal:

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

Now PM2 will automatically restart at boot.

Saving the app list

Once you have started all desired apps, save the app list so it will respawn after reboot:

$ pm2 save

Done

You can control machbase-neo with the following commands:

$ pm2 start neo
$ pm2 status neo
$ pm2 stop neo
$ pm2 restart neo

$ pm2 logs neo
$ pm2 monit
Last updated on