From 3d9e7d1dbce681f9cc5ca2e2ac58547473f3db9a Mon Sep 17 00:00:00 2001 From: haimd Date: Tue, 19 Jan 2021 15:10:48 +0700 Subject: [PATCH] Chay serverlite voi pm2 --- monitor/setup/pm2setup.sh | 61 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 monitor/setup/pm2setup.sh diff --git a/monitor/setup/pm2setup.sh b/monitor/setup/pm2setup.sh new file mode 100644 index 0000000..f7e3d9a --- /dev/null +++ b/monitor/setup/pm2setup.sh @@ -0,0 +1,61 @@ +#!/bin/bash +# xoa run tmux server lite trong rc.local +echo "setup rc.local" +echo '#!/bin/sh -e +# +# rc.local +# +# This script is executed at the end of each multiuser runlevel. +# Make sure that the script will "" on success or any other +# value on error. +# +# In order to enable or disable this script just change the execution +# bits. +# +# By default this script does nothing. + + +#/boot/fan.sh & + +if [ ! -d /var/run/sshd ]; then + mkdir /var/run/sshd + chmod 0755 /var/run/sshd + systemctl restart ssh +time_begin=$(date) +echo "Begin rc.local. Time restart: $time_begin" >> /root/monitor/log/rc_local.log +echo "nameserver 8.8.8.8" > /etc/resolv.conf +# tmux new -d -s server_js 'node /root/BiFace_Server_Config_API/server.js' +exit 0' > /etc/rc.local +# Cai dat PM2 run Server lite +sudo apt install npm +npm install pm2 -g +pm2 install pm2-logrotate + +cd /root/monitor/setup/ +pm2 ecosystem +echo " +module.exports = { + apps : [ + { + name: 'Server_lite', + cwd: '/root/BiFace_Server_Config_API', + script: 'server.js', + args: '', + interpreter: 'node', + restart_delay: 1000, + cron_restart: '0 0 * * *', + watch: false, + time: true + } +] +}; +" > ecosystem.config.js +# Khởi chạy pm2 vs cấu hình vừa sửa +pm2 reload ecosystem.config.js + +# Cài đặt pm2 khởi động cùng Win/Ubuntu +pm2 startup +# Copy-paste và chạy dòng script hiện trên màn hình +pm2 save +reboot +exit 0