install.sh 937 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/bin/bash
  2. set -e
  3. # NOTE: App is installed to /opt/$APP_COMPARTMENT/$APP_MODULE
  4. APP_COMPARTMENT="nsq-server"
  5. APP_MODULE="nsq-server"
  6. if [ $UID -ne 0 ]; then
  7. echo "请用root用户运行当前脚本 (su root)" && exit 1
  8. fi
  9. if [ -r /opt/$APP_COMPARTMENT/$APP_MODULE ];then
  10. echo "/opt/$APP_COMPARTMENT/$APP_MODULE 文件夹已存在,请重命名旧版本文件后再尝试"
  11. exit
  12. fi
  13. root_dir=/opt/$APP_COMPARTMENT
  14. if [ ! -d "$root_dir" ]; then
  15. mkdir -p $root_dir
  16. fi
  17. tar zxf ./$APP_MODULE.tar.gz -C $root_dir
  18. cp -f systemd.service /etc/systemd/system/$APP_MODULE.service
  19. if [ ! -r /opt/$APP_COMPARTMENT/$APP_MODULE ];then
  20. echo "安装失败!"
  21. exit
  22. else
  23. echo "安装成功!"
  24. fi
  25. chmod +x /opt/$APP_COMPARTMENT/$APP_MODULE/*.sh
  26. chmod +x /opt/$APP_COMPARTMENT/$APP_MODULE/bin/*
  27. systemctl daemon-reload
  28. systemctl enable $APP_MODULE
  29. systemctl start $APP_MODULE
  30. echo "$APP_MODULE 已启动"