aws 開機自動啟動sh檔案(jar程式等),命令的新增位置

cocopine發表於2020-11-04

rc.local
要寫在這個下面/etc/rc.d/rc.local

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local
sudo -i sh /app/run_java.sh > /etc/run_java.log

/app/run_java.sh


if [ "`whoami`" != "root" ]; then
  echo "----------------------------"
  echo "Must excute me as following:"
  echo "sudo -E sh run_java.sh"
  echo "----------------------------"
  exit 1
fi

echo "1.copy jar"
read -p "Enter"
cp -rf ./run_java-0.0.1-SNAPSHOT.jar /opt/run_java/run_java-0.0.1-SNAPSHOT.jar

echo "2.kill port"
read -p "Enter"
pkill -KILL -e -c -f run_java-0.0.1-SNAPSHOT.jar

echo "3.export "
read -p "Enter"
export HOME="/home/run_java"

echo "4.run"
read -p "Enter"
nohup /usr/lib/jvm/jdk-11.0.1/bin/java -jar /opt/run_java/run_java-0.0.1-SNAPSHOT.jar --server.port=8080 > /opt/run_java/run_java.log 2>&1 &
sleep 10
cat /opt/run_java/run_java.log
pgrep -f run_java-0.0.1-SNAPSHOT.jar

相關文章