暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

使用Bash Shell实现flowable配置文件修改定制

数据库SQL 2020-05-04
1252

1、概要

部署flowable工作流引擎,需要根据所在服务器的IP和MySQL账密信息,修改很多配置项,为方便,这些配置项,采用脚本批处理的方式,将用户在终端输入的信息,进行处理并修改配置项(以往的操作是,先将压缩包解压,再将war包解压,修改配置文件,再将文件打成war包,最后部署测试,及其容易出错)。节省了大量的时间。

脚本完整版地址:

    https://flowable.oss-cn-beijing.aliyuncs.com/semi_auto_deploy_flowable_sample.sh
    复制

    flowable下载地址

      https://github.com/flowable/flowable-engine/releases/tag/flowable-6.3.0
      复制

      2、脚本内容

      脚本做了以下事情:

      • 解压flowable.zip

      • 创建flowable-admin等5个文件夹,并将flowable-admin.war等5个war包依次移动至相对应的文件夹

      • 解压war包 && 进入指定目录,处理配置文件

      • 接受用户输入的配置项各项信息

      • 每一个配置文件输入结束时,会确认是否要继续,正确输入y,则生成application.properies配置文件

      • 错误则输入n,输入指定的数字,进行纠正,直至用户输入y确认成配置文件

      • 将处理好的文件,打包成war包

      3、实现

      如图,使用的时候,保证脚本和压缩包在同一目录下:

      这段代码是获取文件路径

        CURDIR=$(
        cd $(dirname ${BASH_SOURCE[0]})
        pwd
        )
        复制

        这段代码是处理用户输入的内容

          cd flowable-admin/WEB-INF/classes
          rm -rf application.properties
          touch application.properties
          # 提示端口,如果不输入,会有默认值9988
          echo -n "[1]please input the server.port = ? (default is 9988)"
          read port
          if [[ $port == "" ]]; then
          port='9988'
          fi

          echo -n "your server.port is $port"

          echo -n "[13]please input the MySQL server host ip = ? (default is 127.0.0.1)"
          read MySQLHostIp
          if [[ $MySQLHostIp == "" ]]; then
          MySQLHostIp='127.0.0.1'
          fi

          echo -n "[14]please input the MySQL server host port = ? (default is 3306)"
          read MySQLHostPort
          if [[ $MySQLHostPort == "" ]]; then
          MySQLHostPort='3306'
          fi
          复制

          上文说过,如果错了,是可以根据序号修正输入信息的。如果flag不为y,则会一直询问正确输入,直至输入y为止。

            read flag
            while [[ $flag == "n" ]]; do
            echo 'input number 1 to 26, the numbers are not continuous'
            echo 'your number is'
            read aNum
            case $aNum in
            1)
            echo 'number is 1, please fix your [port] current!'
            read line1
            port=$line1
            ;;
            13)
            echo 'number is 13, please fix your [the MySQL server host ip] current!'
            read line13
            MySQLHostIp=$line13
            ;;
            14)
            echo 'number is 14, please fix your [the MySQL server host port] current!'
            read line14
            MySQLHostPort=$line14
            ;;
            *)
            echo 'Error'
            ;;
            esac
            echo -n "confirm,if wrong, please choice 'n' to fix it !, input y/n:"
            read flag
            done
            复制

            最后,使用

              cat >application.properties <<EOF
              复制

              并配合类似:

                spring.datasource.username=$datasourceUsername
                spring.datasource.password=$datasourcePassword
                复制

                将读取终端input的变量值写入要生成的配置文件中。

                4、最后

                使用Bash Shell的好处,不需要再额外部署运行环境,也无需担心三方部署系统对生产机器带来不可预知的错误和问题。

                可以尝试自己的工作或者学习中,有没有需要一个Bash Shell来解决的。

                最后修改时间:2020-05-05 09:17:20
                文章转载自数据库SQL,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

                评论