部署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、脚本内容
脚本做了以下事情:
如图,使用的时候,保证脚本和压缩包在同一目录下:
这段代码是获取文件路径
CURDIR=$( cd $(dirname ${BASH_SOURCE[0]}) pwd)
这段代码是处理用户输入的内容
cd flowable-admin/WEB-INF/classesrm -rf application.propertiestouch application.properties# 提示端口,如果不输入,会有默认值9988echo -n "[1]please input the server.port = ? (default is 9988)"read portif [[ $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 MySQLHostIpif [[ $MySQLHostIp == "" ]]; then MySQLHostIp='127.0.0.1'fi
echo -n "[14]please input the MySQL server host port = ? (default is 3306)"read MySQLHostPortif [[ $MySQLHostPort == "" ]]; then MySQLHostPort='3306'fi
上文说过,如果错了,是可以根据序号修正输入信息的。如果flag不为y,则会一直询问正确输入,直至输入y为止。
read flagwhile [[ $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 flagdone
最后,使用
cat >application.properties <<EOF
并配合类似:
spring.datasource.username=$datasourceUsernamespring.datasource.password=$datasourcePassword
将读取终端input的变量值写入要生成的配置文件中。
4、最后
使用Bash Shell的好处,不需要再额外部署运行环境,也无需担心三方部署系统对生产机器带来不可预知的错误和问题。
可以尝试自己的工作或者学习中,有没有需要一个Bash Shell来解决的。