[关闭]
@cyysu 2017-09-26T07:46:58.000000Z 字数 2851 阅读 1027

PF600_ACQ系统使用说明手册(软件类)

  • 时间:2017年8月25日
  • 作者:chen yuan
  • 描述:简介脚本使用说明以及系统启动所需文件
  • 版本:V2.0

脚本编写


1. 系统登录说明

默认的用户为root 登录密码为mj1234,后续如果更改密码可以采用如下方式

  1. passwd root #使用root执行该命令

2. 脚本使用说明

脚本按照service方式进行编辑,在启动时需要加入启动参数。如:

  1. /bin/bash autostart.sh start

脚本采用低耦合方式进行编写,将统一功能的代码进行封装。为了确保运行在当前目录,可以在脚本中看到cd ${DIRECTORY},在后续脚本的升级中,将需要运行的文件封装成变量。

  1. #! /bin/bash
  2. #chkconfig: 2345 80 90
  3. #description: autostart centos scripts
  4. #processname: autostartPython
  5. DIRECTORY=/opt/build
  6. FILE=demo.py
  7. # Copy config file to the build directory
  8. findFile(){
  9. # add copy config file to build directory
  10. cd $DIRECTORY
  11. for file in `ls`
  12. do
  13. if [ -d $file ];then
  14. cd $file && \cp ./*.json ../ && cd ..
  15. fi
  16. done
  17. }
  18. # Main function
  19. main(){
  20. python demo.py
  21. }
  22. # Start function
  23. do_start(){
  24. #Compile build directory
  25. if [ -d $DIRECTORY ];then
  26. echo "`date`: Enter this directory!!!"
  27. findFile
  28. else
  29. echo -e "\033[41m`date`: ${DIRECTORY} may not exit!!! Ready to compile file to produce!!!\033[0m "
  30. cd /opt
  31. python setup.py PF600_ACQ && cd ${DIRECTORY}
  32. findFile
  33. #exit
  34. fi
  35. #make sure current directory is /opt/build
  36. cd ${DIRECTORY}
  37. # Add start File to build
  38. if [ -e $FILE ];then
  39. echo "File exist success! Ready to run program!!!"
  40. main
  41. else
  42. echo -e "\033[41m`date`: Scripts start failed!!! ${FILE} may not exit!!! Ready to produce bootfile!!!\033[0m "
  43. cd /opt && cp demo.py ${DIRECTORY} && cd ${DIRECTORY}
  44. main
  45. #exit
  46. fi
  47. }
  48. case "$1" in
  49. start)
  50. do_start
  51. #cd /opt
  52. #python mqttTest.py
  53. ;;
  54. stop)
  55. ;;
  56. status)
  57. echo $?
  58. ;;
  59. *)
  60. echo "Usage autostart.sh [start|stop]" >&2
  61. exit 3
  62. esac

3. 系统启动说明

系统系统所需要的文件包括如下:

脚本具有自动执行编译过程,并生成build目录,同时会将配置文件拷贝到需要的文件夹目录下。并且如果脚本中不具有该目录会自动创建并进行编译操作

4. 安装系统环境脚本

  1. YUM=/var/run/yum.pid
  2. ## install dependence
  3. dependence(){
  4. echo -e "\033[41m `date`: Begin to install software!!!\033[0m"
  5. yum install -y vim epel-release python gcc python-devel Cython 2&>/dev/null
  6. }
  7. ## update system
  8. update(){
  9. echo -e "\033[41m `date`: Begin to update system!!!\033[0m"
  10. if [ $? -eq 0 ];then
  11. yum -y update
  12. if [ $? -eq 0 ];then
  13. yum install -y python-pip
  14. fi
  15. else
  16. if [ -e ${YUM} ];then
  17. rm -rf ${YUM}
  18. yum -y update
  19. yum install -y python-pip
  20. fi
  21. fi
  22. }
  23. ## install python dependence software
  24. pythonSoftware(){
  25. echo -e "\033[41m `date`: Begin to install python dependence software!!!\033[0m"
  26. if [ $? -eq 0 ];then
  27. pip install paho-mqtt
  28. fi
  29. if [ $? -eq 0 ];then
  30. pip install modbus-tk
  31. fi
  32. }
  33. # main function
  34. case "$1" in
  35. start)
  36. dependence
  37. update
  38. pythonSoftware
  39. ;;
  40. stop)
  41. ;;
  42. status)
  43. echo $?
  44. ;;
  45. *)
  46. echo "Usage autostart.sh [start|stop]" >&2
  47. exit 3
  48. esac

5. 使用教程

第一步: 将文件夹所有内容放到opt目录下

  1. cd 文件路径
  2. \cp -rf ./* /opt

第二步: 执行脚本,添加系统系统服务

  1. ./autostart.sh #生成build目录
  2. cp ./autostart.service /lib/systemd/system/
  3. systemctl enable autostart.service

然后编辑文件/etc/rc.local

  1. 在文件中填入 /bin/bash /opt/autostart.sh start

第三步: 删除源码

  1. rm -rf ./PF600_ACQ #删除要慎重

第四步: 重启验证

  1. reboot
  2. systemctl status autostart.service # 如果看到active代表成功启动,直观上没有红颜色字体

系统附带功能

1. 具有了ifconfig命令和netstat命令,方便我们查看服务是否启动和查看网络
2. 具有NFS功能,挂载只需要 mount -t nfs ip:/opt /你本地电脑的位置
3. 防火墙默认关闭,selinux开机会运行我们的脚本,会暂时关闭,不影响程序运行。
4. 系统目录中不可含有以build为名字的文件

重点强调 selinux不可以禁止,否则启动不了系统
重点强调 selinux不可以禁止,否则启动不了系统
重点强调 selinux不可以禁止,否则启动不了系统
重点强调 selinux不可以禁止,否则启动不了系统
重点强调 selinux不可以禁止,否则启动不了系统

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注