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,6 +43,32 @@ if [ -z "$(grep 'orbit_sites' nginx.conf)" ]; then
fi
cd $org_pwd
sudo apt-get install gnupg -y
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 [ $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
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
@ -41,8 +83,8 @@ 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 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
@ -54,13 +96,13 @@ 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!"
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* mongodb-clients -y
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 -
@ -77,7 +119,7 @@ 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 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
@ -88,13 +130,13 @@ else
sudo ln -s /usr/bin/mongosh /usr/bin/mongo
fi
if [ -e /tmp/mongodb-27017.sock ]; then
echo "Mongo start success!"
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* mongodb-clients -y
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 -
@ -109,20 +151,24 @@ else
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
echo "Mongo start success!"
push_messages "Mongo start success!"
else
echo "mongo not yet start!"
echo "Please check mongo status!"
push_messages "mongo not yet start!"
push_messages "Please check mongo status!"
fi
else
echo "mongo not yet start!"
echo "Please check mongo status!"
push_messages "mongo not yet start!"
push_messages "Please check mongo status!"
fi
fi
else
echo "mongo not yet start!"
echo "Please check mongo status!"
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,8 +172,12 @@ create)
d="$(dirname $2)"
site_name="$(basename $2)"
if [[ $d != '.' ]]; then
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