Thursday, March 15, 2018

How to Keep parse server dashboard running or start at system boot

Parse-Dashboard-

By-Default parse dashboard works until your terminal is active, once your connection break parse dashboard will not be available.
We can use two methods to keep dashboard running always.

Method 1- Use nohup command.


Step 1- use nohup command with parse dashboard
 Use nohup command to keep running parse dashboard in the background. use the command below.
Go to the parse dashboard directory-
 root@Server16:~#  cd /opt/parse-dashboard
use nohup "parse command" &


root@Server16:/opt/parse-dashboard# nohup parse-dashboard --config parse-dashboard-config.json --allowInsecureHTTP false &

nohup command will keep running parse dashboard in the background


Step 2- setup this command to run at system boot.
above command will help us to run parse dashboard in the background but in case our server gets the reboot or crashed due to power failure or other reason. In such case, we need to make sure to run our parse dashboard at system boot up. follow the steps below to run dashboard at system boot.

open and edit rc.local file
root@Server16:~# vi /etc/rc.local
Append the parse dashboard path then command to start parse dashboard. Add the red highlighted line to your rc.local, make sure you are adding both the line before exit 0.
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
#path of parse dashboard
cd /opt/parse-dashboard
# Command to start parse dashboard in the backgroupnd
nohup parse-dashboard --config parse-dashboard-config.json --allowInsecureHTTP false &
exit 0
Your file should be like above in the screenshot

Method 2- Use PM2 npm module to start parse dashboard.

We can  PM2 command to start, stop and check the status of parse dashboard. The advantage is we can stop, start and check the status of our dashboard anytime. Follow the steps below to make PM2 command available in your environment.
Step 1- Install PM2
To install PM2 on your Linux machine use command below.
sudo npm install -g pm2
Once pm2 installed, 
Step 2- Create parse-dashboard.json file.
create a script to make parse dashboard available globally at Linux shell.
Create a parse-dashboard.json file using vim editor.
root@Server16:~# vi parse-dashboard.json
Append the follow lines and change the highlighted line with your path
{
  "apps" : [{
    "name"        : "parse-dashboard-wrapper",
    "script"      : "/usr/bin/parse-dashboard",
    "watch"       : true,
    "merge_logs"  : true,
    "cwd"         : "/opt/parse-dashboard",
    "args"         : "--config /opt/parse-dashboard/parse-dashboard-config.json --allowInsecureHTTP=1"
  }]
}
Save and exit from the editor.
Step 3- Start parse dashboard.
root@Server16:~# pm2 start parse-deshboard.json
Parse dashboard is up and running.
Step 4- Check status:
root@Server16:~# pm2 status parse-deshboard.json
Step 4-Check status of specific pm2 ID
To check the detail of command use ID of running app
root@Server16:~# pm2 show 0
In the screenshot below you will find Script path and executed command.

Step 5- Mark pm2 command execute during system boot.
Your application will be available until the system is up once your system boot up you again need to run this command to make available your dashboard.
Let's set our command to execute during system boot.
open and edit rc.local file
root@Server16:~# vi /etc/rc.local
Add the following line before exit 0 line
# bits.
#
# By default this script does nothing.
#Start parse dashboard at system boot up
pm2 start /home/amar/parse-deshboard.json
exit 0

Save and exit from the file.

Now, your parse dashboard will be available if your system gets the reboot.


No comments:

Post a Comment