Update scripts.

This commit is contained in:
BoHung Chiu 2022-08-25 09:39:48 +08:00
parent fc59db8eed
commit 2d2cfb805f
2 changed files with 163 additions and 108 deletions

View File

@ -16,6 +16,22 @@ wget http://gitlab.tp.rulingcom.com/erictyl/install_r45_on_ubuntu_1804lts_doc/-/
bash install_nginx.sh
sudo nginx -t
nginx_status="$(echo $?)"
messages_logs=""
function push_messages(){
if [[ ! -z "$1" ]]; then
if [ -z "$messages_logs" ]; then
messages_logs="$1"
else
messages_logs="$messages_logs
$1"
fi
fi
}
function write_messages(){
echo "$messages_logs"
echo "$messages_logs" > install_orbit_environment.log
echo "Logs stored in install_orbit_environment.log!"
}
if [ $nginx_status != "0" ]; then
sudo sed -i 's/\([^#]include \/etc\/nginx\/sites-enabled\/*\)/\#\1/g' /etc/nginx/nginx.conf
fi
@ -27,102 +43,132 @@ if [ -z "$(grep 'orbit_sites' nginx.conf)" ]; then
fi
cd $org_pwd
sudo apt-get install gnupg -y
# install mongod 6.0
wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -
if [[ $ubuntu_version =~ '20' ]] || [[ $ubuntu_version =~ '21' ]]; then
sudo wget -nc http://archive.ubuntu.com/ubuntu/pool/main/o/openssl1.0/libssl1.0-dev_1.0.2n-1ubuntu5_amd64.deb
sudo dpkg -i libssl1.0-dev_1.0.2n-1ubuntu5_amd64.deb
sudo wget -nc http://archive.ubuntu.com/ubuntu/pool/main/o/openssl1.0/libssl1.0.0_1.0.2n-1ubuntu5_amd64.deb
sudo dpkg -i libssl1.0.0_1.0.2n-1ubuntu5_amd64.deb
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
elif [[ $ubuntu_version =~ '18' ]] || [[ $ubuntu_version =~ '19' ]]; then
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
else
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
fi
sudo apt-get update
sudo apt-get install -y mongodb-org=6.0.1 mongodb-org-database=6.0.1 mongodb-org-server=6.0.1 mongodb-mongosh mongodb-org-mongos=6.0.1 mongodb-org-tools=6.0.1
sudo apt-get install -y mongodb-clients
sudo service mongod stop
sudo rm -f /var/lib/mongodb/mongod.lock
sudo rm -f /tmp/mongodb-27017.sock
sudo chown mongodb:mongodb /var/lib/mongodb -R
sudo chown mongodb:mongodb /var/log/mongodb -R
sudo service mongod restart
sleep 10
if [[ ! -e /usr/bin/mongo ]]; then
sudo ln -s /usr/bin/mongosh /usr/bin/mongo
fi
if [ -e /tmp/mongodb-27017.sock ]; then
echo "Mongo start success!"
else
if [[ $ubuntu_version =~ '14' ]]; then
wget -qO - https://www.mongodb.org/static/pgp/server-3.2.asc | sudo apt-key add -
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
sudo apt-get update
sudo apt-get install -y mongodb-org=3.2.22 mongodb-org-server=3.2.22 mongodb-org-shell=3.2.22 mongodb-org-mongos=3.2.22 mongodb-org-tools=3.2.22
sudo service mongod stop
sudo rm -f /var/lib/mongodb/mongod.lock
sudo rm -f /tmp/mongodb-27017.sock
sudo chown mongodb:mongodb /var/lib/mongodb -R
sudo chown mongodb:mongodb /var/log/mongodb -R
sudo service mongod restart
sleep 10
mongo --eval "db.version()" --quiet
exit_code="$(echo $?)"
#if mongo 6 core dump, then install mongo 5
if [ $exit_code != 0 ] && [ $exit_code != 1 ]; then
sudo apt-get purge mongodb-org* mongodb-clients -y
sudo rm -rf /var/log/mongodb
sudo rm -rf /var/lib/mongodb
wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
# install mongod 5.0
if [[ $ubuntu_version =~ '20' ]] || [[ $ubuntu_version =~ '21' ]]; then
sudo wget -nc http://archive.ubuntu.com/ubuntu/pool/main/o/openssl1.0/libssl1.0-dev_1.0.2n-1ubuntu5_amd64.deb
sudo dpkg -i libssl1.0-dev_1.0.2n-1ubuntu5_amd64.deb
sudo wget -nc http://archive.ubuntu.com/ubuntu/pool/main/o/openssl1.0/libssl1.0.0_1.0.2n-1ubuntu5_amd64.deb
sudo dpkg -i libssl1.0.0_1.0.2n-1ubuntu5_amd64.deb
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
elif [[ $ubuntu_version =~ '18' ]] || [[ $ubuntu_version =~ '19' ]]; then
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
else
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
fi
sudo apt-get update
sudo apt-get install -y mongodb-org=5.0.11 mongodb-org-database=5.0.11 mongodb-org-server=5.0.11 mongodb-org-shell=5.0.11 mongodb-org-mongos=5.0.11 mongodb-org-tools=5.0.11 mongodb-mongosh
sudo rm -f /var/lib/mongodb/mongod.lock
sudo rm -f /tmp/mongodb-27017.sock
sudo chown mongodb:mongodb /var/lib/mongodb -R
sudo chown mongodb:mongodb /var/log/mongodb -R
sudo service mongod restart
sleep 10
if [[ ! -e /usr/bin/mongo ]]; then
sudo ln -s /usr/bin/mongosh /usr/bin/mongo
fi
if [ -e /tmp/mongodb-27017.sock ]; then
echo "Mongo start success!"
else
mongo --eval "db.version()" --quiet
exit_code="$(echo $?)"
#if mongo 5 core dump, then install mongo 4.4
if [ $exit_code != 0 ] && [ $exit_code != 1 ]; then
sudo apt-get purge mongodb-org* mongodb-clients -y
sudo rm -rf /var/log/mongodb
sudo rm -rf /var/lib/mongodb
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
if [[ $ubuntu_version =~ '20' ]] || [[ $ubuntu_version =~ '21' ]]; then
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
elif [[ $ubuntu_version =~ '18' ]] || [[ $ubuntu_version =~ '19' ]]; then
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
else
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
fi
sudo apt-get update
sudo apt-get install -y mongodb-org=4.4.11 mongodb-org-server=4.4.11 mongodb-org-shell=4.4.11 mongodb-org-mongos=4.4.11 mongodb-org-tools=4.4.11
sudo service mongod restart
sleep 10
if [ -e /tmp/mongodb-27017.sock ]; then
echo "Mongo start success!"
else
echo "mongo not yet start!"
echo "Please check mongo status!"
fi
else
echo "mongo not yet start!"
echo "Please check mongo status!"
fi
fi
if [ $exit_code != 0 ] && [ $exit_code != 1 ]; then #mongo core dump
push_messages "Mongo 3.2 core dump!"
push_messages "Please install mongod by yourself!"
else
echo "mongo not yet start!"
echo "Please check mongo status!"
if [ -e /tmp/mongodb-27017.sock ]; then
push_messages "Mongo start success!"
else
push_messages "mongo not yet start!"
push_messages "Please check mongo status!"
fi
fi
else
# install mongod 6.0
wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -
if [[ $ubuntu_version =~ '20' ]] || [[ $ubuntu_version =~ '21' ]]; then
sudo wget -nc http://archive.ubuntu.com/ubuntu/pool/main/o/openssl1.0/libssl1.0-dev_1.0.2n-1ubuntu5_amd64.deb
sudo dpkg -i libssl1.0-dev_1.0.2n-1ubuntu5_amd64.deb
sudo wget -nc http://archive.ubuntu.com/ubuntu/pool/main/o/openssl1.0/libssl1.0.0_1.0.2n-1ubuntu5_amd64.deb
sudo dpkg -i libssl1.0.0_1.0.2n-1ubuntu5_amd64.deb
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
elif [[ $ubuntu_version =~ '18' ]] || [[ $ubuntu_version =~ '19' ]]; then
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
else
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
fi
sudo apt-get update
sudo apt-get remove mongodb-clients --purge
sudo apt-get install -y mongodb-org=6.0.1 mongodb-org-database=6.0.1 mongodb-org-server=6.0.1 mongodb-mongosh mongodb-org-mongos=6.0.1 mongodb-org-tools=6.0.1
sudo service mongod stop
sudo rm -f /var/lib/mongodb/mongod.lock
sudo rm -f /tmp/mongodb-27017.sock
sudo chown mongodb:mongodb /var/lib/mongodb -R
sudo chown mongodb:mongodb /var/log/mongodb -R
sudo service mongod restart
sleep 10
if [[ ! -e /usr/bin/mongo ]]; then
sudo ln -s /usr/bin/mongosh /usr/bin/mongo
fi
if [ -e /tmp/mongodb-27017.sock ]; then
push_messages "Mongo start success!"
else
mongo --eval "db.version()" --quiet
exit_code="$(echo $?)"
#if mongo 6 core dump, then install mongo 5
if [ $exit_code != 0 ] && [ $exit_code != 1 ]; then
sudo apt-get purge mongodb-org* -y
sudo rm -rf /var/log/mongodb
sudo rm -rf /var/lib/mongodb
wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
# install mongod 5.0
if [[ $ubuntu_version =~ '20' ]] || [[ $ubuntu_version =~ '21' ]]; then
sudo wget -nc http://archive.ubuntu.com/ubuntu/pool/main/o/openssl1.0/libssl1.0-dev_1.0.2n-1ubuntu5_amd64.deb
sudo dpkg -i libssl1.0-dev_1.0.2n-1ubuntu5_amd64.deb
sudo wget -nc http://archive.ubuntu.com/ubuntu/pool/main/o/openssl1.0/libssl1.0.0_1.0.2n-1ubuntu5_amd64.deb
sudo dpkg -i libssl1.0.0_1.0.2n-1ubuntu5_amd64.deb
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
elif [[ $ubuntu_version =~ '18' ]] || [[ $ubuntu_version =~ '19' ]]; then
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
else
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
fi
sudo apt-get update
sudo apt-get install -y mongodb-org=5.0.11 mongodb-org-database=5.0.11 mongodb-org-server=5.0.11 mongodb-mongosh mongodb-org-shell=5.0.11 mongodb-org-mongos=5.0.11 mongodb-org-tools=5.0.11
sudo rm -f /var/lib/mongodb/mongod.lock
sudo rm -f /tmp/mongodb-27017.sock
sudo chown mongodb:mongodb /var/lib/mongodb -R
sudo chown mongodb:mongodb /var/log/mongodb -R
sudo service mongod restart
sleep 10
if [[ ! -e /usr/bin/mongo ]]; then
sudo ln -s /usr/bin/mongosh /usr/bin/mongo
fi
if [ -e /tmp/mongodb-27017.sock ]; then
push_messages "Mongo start success!"
else
mongo --eval "db.version()" --quiet
exit_code="$(echo $?)"
#if mongo 5 core dump, then install mongo 4.4
if [ $exit_code != 0 ] && [ $exit_code != 1 ]; then
sudo apt-get purge mongodb-org* -y
sudo rm -rf /var/log/mongodb
sudo rm -rf /var/lib/mongodb
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
if [[ $ubuntu_version =~ '20' ]] || [[ $ubuntu_version =~ '21' ]]; then
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
elif [[ $ubuntu_version =~ '18' ]] || [[ $ubuntu_version =~ '19' ]]; then
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
else
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
fi
sudo apt-get update
sudo apt-get install -y mongodb-org=4.4.11 mongodb-org-server=4.4.11 mongodb-org-shell=4.4.11 mongodb-org-mongos=4.4.11 mongodb-org-tools=4.4.11
sudo service mongod restart
sleep 10
if [[ ! -e /usr/bin/mongo ]]; then
sudo ln -s /usr/bin/mongosh /usr/bin/mongo
fi
if [ -e /tmp/mongodb-27017.sock ]; then
push_messages "Mongo start success!"
else
push_messages "mongo not yet start!"
push_messages "Please check mongo status!"
fi
else
push_messages "mongo not yet start!"
push_messages "Please check mongo status!"
fi
fi
else
push_messages "mongo not yet start!"
push_messages "Please check mongo status!"
fi
fi
fi
# build ImageMagick and install
@ -209,31 +255,36 @@ sudo update-rc.d orbit defaults
sudo systemctl enable mongod.service
sudo_crontab_jobs=$(sudo crontab -l)
if [[ "$sudo_crontab_jobs" =~ "@reboot /bin/bash -l -c" ]]; then
echo "Already exist reboot crontab!"
push_messages "Already exist reboot crontab!"
else
echo "Adding reboot crontab!"
echo "$sudo_crontab_jobs"$'\n''@reboot /bin/bash -l -c "rm -f /tmp/mongodb-27017.sock && chown mongodb:mongodb /var/lib/mongodb/ -R && chown mongodb:mongodb /var/log/mongodb -R && /usr/sbin/service mongod restart && /etc/init.d/orbit restart"'| sudo crontab -
push_messages "Adding reboot crontab!"
push_messages "$sudo_crontab_jobs"$'\n''@reboot /bin/bash -l -c "rm -f /tmp/mongodb-27017.sock && chown mongodb:mongodb /var/lib/mongodb/ -R && chown mongodb:mongodb /var/log/mongodb -R && /usr/sbin/service mongod restart && /etc/init.d/orbit restart"'| sudo crontab -
fi
sudo_crontab_jobs=$(sudo crontab -l)
if [[ "$sudo_crontab_jobs" =~ "mongodump -o /" ]]; then
echo "Already exist mongodump crontab!"
push_messages "Already exist mongodump crontab!"
else
echo "Adding mongodump crontab!"
echo "$sudo_crontab_jobs"$'\n''0 3 * * * mongodump -o /home/backup/db/`date "+\%Y\%m\%d"`_db'| sudo crontab -
push_messages "Adding mongodump crontab!"
push_messages "$sudo_crontab_jobs"$'\n''0 3 * * * mongodump -o /home/backup/db/`date "+\%Y\%m\%d"`_db'| sudo crontab -
fi
sudo_crontab_jobs=$(sudo crontab -l)
if [[ `echo "$sudo_crontab_jobs" | grep -P "rm -fr.*/db/"` ]]; then
echo "Already exist remove old mongo backup crontab!"
push_messages "Already exist remove old mongo backup crontab!"
else
echo "Adding remove old mongo backup crontab!"
echo "$sudo_crontab_jobs"$'\n''0 4 * * * rm -fr /home/backup/db/`date --date="1 week ago" "+\%Y\%m\%d"`_db'| sudo crontab -
push_messages "Adding remove old mongo backup crontab!"
push_messages "$sudo_crontab_jobs"$'\n''0 4 * * * rm -fr /home/backup/db/`date --date="1 week ago" "+\%Y\%m\%d"`_db'| sudo crontab -
fi
sudo_crontab_jobs=$(sudo crontab -l)
if [[ "$sudo_crontab_jobs" =~ "/usr/bin/rsnapshot" ]]; then
echo "Already exist rsnapshot crontab!"
push_messages "Already exist rsnapshot crontab!"
else
echo "Adding rsnapshot crontab!"
echo "$sudo_crontab_jobs"$'\n''15 4 * * * /usr/bin/rsnapshot daily'| sudo crontab -
push_messages "Adding rsnapshot crontab!"
push_messages "$sudo_crontab_jobs"$'\n''15 4 * * * /usr/bin/rsnapshot daily'| sudo crontab -
fi
echo "Finish setting orbit environment!"
echo "Please install orbit web app and setting nginx for single web by yourself!"
push_messages "Finish setting orbit environment!"
push_messages "Please install orbit web app and setting nginx for single web by yourself!"
push_messages "You can use the following command to create web!"
push_messages "$ sudo /etc/init.d/orbit create \$site_path"
push_messages "Ex: sudo /etc/init.d/orbit create orbit_sites/orbit"
push_messages "Ex: sudo /etc/init.d/orbit create /home/rulingcom/orbit_sites/orbit"
write_messages

View File

@ -172,7 +172,11 @@ create)
d="$(dirname $2)"
site_name="$(basename $2)"
if [[ $d != '.' ]]; then
ORBIT_SITES="$ORBIT_SITES/$d"
if [[ "${d:0:1}" == "/" ]]; then
ORBIT_SITES="$d"
else
ORBIT_SITES="$ORBIT_SITES/$d"
fi
fi
test -s "$NGINX_ORBIT_SITES/$site_name" && echo "Site $site_name already exist." && exit 0
test -s "$ORBIT_SITES/$site_name" && echo "File $ORBIT_SITES/$site_name already exist." && exit 0