提交 86f0e70e 编写于 作者: 智布道's avatar 智布道 👁

🔇

上级 824214f7
package com.zyd.blog.spider.processor;
import java.util.List;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @date 2018/7/24 11:08
* @since 1.0
*/
public class Drug {
private String fileName;
private String shortName;
private String title;
private List<DrugItem> items;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public List<DrugItem> getItems() {
return items;
}
public void setItems(List<DrugItem> items) {
this.items = items;
}
public String getShortName() {
if (null == this.shortName || this.shortName.isEmpty()) {
this.shortName = this.getTitle().substring(this.getTitle().indexOf("表") + 1);
this.shortName = this.shortName.replaceAll("年([0-9]{1,1})月", "年0$1月");
// this.shortName = this.shortName.replaceAll("[0-9]{4}年", "");
this.shortName = this.shortName.replaceAll("至([0-9]{1,1})月", "至0$1月");
this.shortName = this.shortName.replaceAll("月([0-9]{1,1})日", "月0$1日");
this.shortName = this.shortName.replaceAll("([年月日()()])", "");
this.shortName = this.shortName.replaceAll("至", "-");
this.shortName = this.shortName.replaceAll("签发期:", "");
this.shortName = this.shortName.replaceAll("- 1", "");
}
return shortName;
}
public static void main(String[] args) {
String str = "中检院生物制品批签发信息公示表(签发日期:2017年12月21日至2018年2月2日)- 1";
Drug drug = new Drug();
drug.setTitle(str);
System.out.println(drug.getShortName());
System.out.println(drug.getFileName());
}
public String getFileName() {
String fileName = this.getTitle().substring(0, this.getTitle().indexOf("表") + 1);
fileName += this.getTitle().substring(this.getTitle().indexOf("表") + 1)
.replaceAll("[0-9]{1,2}日至", "-")
.replaceAll("[0-9]{1,2}日)", ")")
.replaceAll("签发日期:", "")
.replaceAll("- 1", "");
return fileName;
}
}
package com.zyd.blog.spider.processor;
import com.github.crab2died.annotation.ExcelField;
/**
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @date 2018/7/24 11:08
* @since 1.0
*/
public class DrugItem {
@ExcelField(title = "序号", order = 1)
private String num;
@ExcelField(title = "制品名称", order = 2)
private String name;
@ExcelField(title = "规格", order = 3)
private String guige;
@ExcelField(title = "批号", order = 4)
private String pihao;
@ExcelField(title = "批量/进口量", order = 5)
private String piliang;
@ExcelField(title = "有效期至", order = 6)
private String expire;
@ExcelField(title = "生产企业", order = 7)
private String company;
@ExcelField(title = "签发结论", order = 8)
private String result;
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGuige() {
return guige;
}
public void setGuige(String guige) {
this.guige = guige;
}
public String getPihao() {
return pihao;
}
public void setPihao(String pihao) {
this.pihao = pihao;
}
public String getPiliang() {
return piliang;
}
public void setPiliang(String piliang) {
this.piliang = piliang;
}
public String getExpire() {
return expire;
}
public void setExpire(String expire) {
this.expire = expire;
}
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
}
package com.zyd.blog.spider.processor;
import com.github.crab2died.ExcelUtils;
import com.github.crab2died.exceptions.Excel4JException;
import com.github.crab2died.sheet.wrapper.NoTemplateSheetWrapper;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.processor.PageProcessor;
import us.codecraft.webmagic.selector.Html;
import us.codecraft.webmagic.selector.Selectable;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 抓取疫苗信息
*
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
* @version 1.0
* @date 2018/7/23 10:38
* @since 1.0
*/
public class DrugSpiderProcessor implements PageProcessor {
private static List<Drug> drugs = new LinkedList<>();
public static List<Drug> run() {
Spider spider = Spider.create(new DrugSpiderProcessor())
.addUrl(
"http://www.nicpbp.org.cn/CL0108/",
"http://www.nicpbp.org.cn/CL0873/",
"http://www.nicpbp.org.cn/CL0833/",
"http://www.nicpbp.org.cn/CL0792/",
"http://www.nicpbp.org.cn/CL0737/",
"http://www.nicpbp.org.cn/CL0428/"
)
.thread(5);
// 启动爬虫
spider.run();
export();
return drugs;
}
private static void export() {
Long start = System.currentTimeMillis();
List<NoTemplateSheetWrapper> sheets = null;
Map<String, List<Drug>> map = new HashMap<>();
for (Drug drug : drugs) {
List<Drug> list = map.get(drug.getFileName());
if (null == list) {
list = new LinkedList<>();
}
list.add(drug);
map.put(drug.getFileName(), list);
}
for (Map.Entry<String, List<Drug>> stringListEntry : map.entrySet()) {
sheets = new LinkedList<>();
String fileName = stringListEntry.getKey();
List<Drug> drugs = stringListEntry.getValue();
for (Drug drug : drugs) {
sheets.add(new NoTemplateSheetWrapper(drug.getItems(), DrugItem.class, true, drug.getShortName()));
}
try {
String filePath = "D://excel/" + fileName + ".xlsx";
File file = new File(filePath);
if (!file.exists()) {
file.getParentFile().mkdirs();
}
ExcelUtils.getInstance().noTemplateSheet2Excel(sheets, filePath);
} catch (Excel4JException | IOException e) {
e.printStackTrace();
}
}
System.out.println((System.currentTimeMillis() - start) + "ms");
}
private static String html2Text(String content) {
if (StringUtils.isEmpty(content)) {
return null;
}
String regexHtml = "<[^>]+>";
content = content.replaceAll(regexHtml, "").replaceAll(" ", "");
content = content.replaceAll("&quot;", "\"")
.replaceAll("&nbsp;", "")
.replaceAll("\n", " ")
.replaceAll("&amp;", "&")
.replaceAll("&lt;", "<")
.replaceAll("&#39;", "\'")
.replaceAll("&gt;", ">")
.replaceAll("[ \\f\\t\\v]{2,}", "\t");
String regEx = "<.+?>";
Pattern pattern = Pattern.compile(regEx);
Matcher matcher = pattern.matcher(content);
content = matcher.replaceAll("");
return content.trim();
}
@Override
public void process(Page page) {
String source = page.getRequest().getUrl();
System.out.println("source + " + source);
Html pageHtml = page.getHtml();
List<Selectable> trs = pageHtml.xpath("//td[@class='articlecontent1']/table").xpath("//tr").nodes();
Drug drug = new Drug();
drug.setTitle(html2Text(pageHtml.xpath("//td[@class='articletitle1']").get()));
if (CollectionUtils.isNotEmpty(trs)) {
List<DrugItem> items = new LinkedList<>();
DrugItem item = null;
boolean firstRow = true;
for (Selectable tr : trs) {
if (firstRow) {
firstRow = false;
continue;
}
try {
List<Selectable> tds = tr.xpath("//td").nodes();
if (CollectionUtils.isNotEmpty(tds)) {
if (tds.size() <= 1) {
continue;
}
item = new DrugItem();
if (tds.size() == 8) {
// http://www.nicpbp.org.cn/CL0737/5324.html
setItemParams(item, tds, new int[]{0, 1, 2, 3, 4, 5, 6, 7});
} else if (tds.size() == 9) {
// http://www.nifdc.org.cn/directory/web/WS02/CL0833/8512.html
setItemParams(item, tds, new int[]{0, 1, 2, 3, 4, 6, 7, 8});
} else if (tds.size() == 10) {
// http://www.nicpbp.org.cn/CL0792/7776.html
setItemParams(item, tds, new int[]{0, 1, 2, 3, 4, 7, 8, 9});
} else if (tds.size() == 12) {
// http://www.nicpbp.org.cn/CL0903/10477.html
setItemParams(item, tds, new int[]{0, 1, 2, 3, 4, 5, 6, 11});
}
// 过滤掉某些页面的表格里的数据统计部分
if (StringUtils.isEmpty(item.getCompany()) || "――".equals(item.getCompany()) || StringUtils.isEmpty(item.getExpire()) || "――".equals(item.getExpire())) {
continue;
}
try {
String sqlFormat = "INSERT INTO `wx_drug_item` (`product_name`,`specification`,`lot_number`,`lot_size`,`expire`,`company`,`result`, `source_url`) " +
"VALUES('%s','%s','%s','%s','%s','%s','%s', '%s');";
MysqlUtil.initParams();
MysqlUtil.getStatement(String.format(sqlFormat, item.getName(), item.getGuige(), item.getPihao(), item.getPiliang(), item.getExpire(), item.getCompany(), item.getResult(), source)).execute();
MysqlUtil.destroy();
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
items.add(item);
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
drug.setItems(items);
drugs.add(drug);
}
Selectable links = page.getHtml().links();
// 正常页面
List<String> list = links.regex(".*www\\.nicpbp\\.org\\.cn/CL[0-9]{3,5}/[0-9]{1,10}\\.html").all();
if (CollectionUtils.isEmpty(list)) {
// http://www.nifdc.org.cn/directory/web/WS02/CL0833/8898.html
// 特殊页面
list = links.regex(".*www\\.nifdc\\.org\\.cn:/directory/web/WS02/CL[0-9]{3,5}/[0-9]{1,10}\\.html").all();
}
if (CollectionUtils.isEmpty(list)) {
return;
}
Collections.reverse(list);
page.addTargetRequests(list);
}
private void setItemParams(DrugItem item, List<Selectable> tds, int[] indexs) {
if (indexs.length < 8) {
return;
}
item.setNum(html2Text(tds.get(indexs[0]).get()));
item.setName(html2Text(tds.get(indexs[1]).get()));
item.setGuige(html2Text(tds.get(indexs[2]).get()));
item.setPihao(html2Text(tds.get(indexs[3]).get()));
item.setPiliang(html2Text(tds.get(indexs[4]).get()));
item.setExpire(html2Text(tds.get(indexs[5]).get()));
item.setCompany(html2Text(tds.get(indexs[6]).get()));
item.setResult(html2Text(tds.get(indexs[7]).get()));
}
@Override
public Site getSite() {
return Site.me()
.setCharset("GB2312")
.setSleepTime(2000)
.setRetryTimes(2)
.setUserAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36");
}
}
/**
* Copyright © 2017 Innodev. All rights reserved.
* Mysql数据库操作工具类
*
* @Package: uk.co.quidos.framework.utils
* @author: zhyd
* @date: 2017年5月12日 上午11:37:31
* @version: V1.0
*/
package com.zyd.blog.spider.processor;
import org.apache.commons.lang3.StringUtils;
import java.sql.*;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* Mysql数据库操作工具类<br>
*
* @ClassName: MysqlUtil
* @author: zhyd
* @date: 2017年5月12日 上午11:37:31
*/
public class MysqlUtil {
private static final String KEY_DRIVER_CLASS_NAME = "driverClassName";
private static final String KEY_URL = "url";
private static final String KEY_USERNAME = "username";
private static final String KEY_PASSWORD = "password";
private static final String KEY_DATABASE_NAME = "databaseName";
private static final String KEY_IS_LOAD_PARAMS = "isLoadParams";
// 链接数据库的参数信息
private static ThreadLocal<Map<String, String>> initParamMap = ThreadLocal.withInitial(() -> {
Map<String, String> map = new ConcurrentHashMap<String, String>();
map.put(KEY_IS_LOAD_PARAMS, "false");
return map;
});
// 数据库操作对象
private static ThreadLocal<Connection> connection = new ThreadLocal<Connection>();
private static ThreadLocal<Statement> statement = new ThreadLocal<Statement>();
private static ThreadLocal<PreparedStatement> preparedStatement = new ThreadLocal<PreparedStatement>();
/**
* 通过指定的配置文件 初始化数据库链接参数
*
* @return void
*/
public static void initParams() {
if (getValue(KEY_IS_LOAD_PARAMS).equalsIgnoreCase("true")) {
return;
}
Map<String, String> map = new ConcurrentHashMap<>(10);
map.put(KEY_DRIVER_CLASS_NAME, "com.mysql.jdbc.Driver");
map.put(KEY_URL, "jdbc:mysql://localhost:3306/blog?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&useSSL=false&allowPublicKeyRetrieval=true");
map.put(KEY_USERNAME, "root");
map.put(KEY_PASSWORD, "root");
map.put(KEY_IS_LOAD_PARAMS, "true");
initParamMap.set(map);
}
/**
* 获取数据库链接
*
* @throws ClassNotFoundException
* @throws SQLException
* @return Connection
*/
public static Connection getConnection() throws ClassNotFoundException, SQLException {
if (connection.get() == null) {
Class.forName(getValue(KEY_DRIVER_CLASS_NAME));
connection.set(
DriverManager.getConnection(getValue(KEY_URL), getValue(KEY_USERNAME), getValue(KEY_PASSWORD)));
}
return connection.get();
}
/**
* 获取Statement
*
* @throws ClassNotFoundException
* @throws SQLException
* @return Statement
*/
public static Statement getStatement() throws ClassNotFoundException, SQLException {
if (statement.get() == null) {
statement.set(getConnection().createStatement());
}
return statement.get();
}
/**
* 获取PreparedStatement
*
* @param sql
* @throws ClassNotFoundException
* @throws SQLException
* @return PreparedStatement
*/
public static PreparedStatement getStatement(String sql) throws ClassNotFoundException, SQLException {
if (preparedStatement.get() == null) {
preparedStatement.set(getConnection().prepareStatement(sql));
}
return preparedStatement.get();
}
/**
* 获取数据库名
*
* @return String
*/
public static String getDatabaseName() {
if (StringUtils.isEmpty(getValue(KEY_DATABASE_NAME))) {
int charIndex = getValue(KEY_URL).indexOf("?");
if (charIndex != -1) {
return getValue(KEY_URL).substring(getValue(KEY_URL).lastIndexOf("/") + 1, charIndex);
}
}
return getValue(KEY_DATABASE_NAME);
}
/**
* 获取map值
*
* @param key
* @return String
*/
private static String getValue(String key) {
Map<String, String> map = initParamMap.get();
if (map != null) {
return map.get(key);
}
return "";
}
/**
* 销毁资源
*
* @return boolean
*/
public static boolean destroy() {
// 关闭资源
close(connection.get(), statement.get(), preparedStatement.get());
// 删除当前线程局部变量的值
connection.remove();
statement.remove();
preparedStatement.remove();
initParamMap.remove();
return true;
}
/**
* 关闭资源
*
* @param closeables
* 待关闭的资源对象
* @return void
*/
public static void close(AutoCloseable... closeables) {
if (closeables != null && closeables.length > 0) {
for (AutoCloseable closeable : closeables) {
if (closeable != null) {
try {
closeable.close();
closeable = null;
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
}
#!/bin/bash
# 部署目录
ROOT_DIR="/var/www/site/oneblog/$2"
# 部署的项目名
APP_NAME=blog-$2.jar
NOW_DATE=$(date +%c)
usage() {
echo "
Copyright @ https://www.zhyd.me . Current Version : v1.0.0
使用方法:
oneblog [options] [modules]
[options]
start : 启动
stop : 停止
restart : 重启
status : 状态
log : 实时监控日志
[modules]
web : 前台程序(blog-web)
admin : 后台程序(blog-admin)
示例:
oneblog start web
oneblog stop web
oneblog restart web
oneblog status web
oneblog log web
注:如果脚本无法执行(报异常),请使用dos2unix命令编译(需先安装:yum install dos2unix)
"
exit 1
}
is_exist_dir() {
if [[ -d "${ROOT_DIR}" ]]; then
return 1
else
return 0
fi
}
is_running(){
pid=`ps -ef|grep $APP_NAME|grep -v grep|awk '{print $2}' `
if [ -z "${pid}" ]; then
return 1
else
return 0
fi
}
start(){
is_running
if [ $? -eq "0" ]; then
echo "${APP_NAME} 正在运行。 pid=${pid} ."
else
nohup java -server -Xms256m -Xmx512m -jar ${ROOT_DIR}/$APP_NAME &
echo "${APP_NAME}启动成功,请查看日志确保运行正常。"
fi
}
stop(){
is_running
if [ $? -eq "0" ]; then
kill -9 $pid
echo "${pid} 进程已被杀死,程序停止运行"
else
echo "${APP_NAME} 未运行!"
fi
}
status(){
is_running
if [ $? -eq "0" ]; then
echo "${APP_NAME} 正在运行。Pid is ${pid}"
else
echo "${APP_NAME} 未运行!"
fi
}
log(){
echo "日志文件位置:${ROOT_DIR}/nohup.out"
tail -f ${ROOT_DIR}/nohup.out
}
restart(){
stop
start
log
}
is_exist_dir
if [ $? != 0 ]; then
echo "当前时间:${NOW_DATE}"
case "$1" in
"start")
start
;;
"stop")
stop
;;
"status")
status
;;
"restart")
restart
;;
"log")
log
;;
*)
usage
;;
esac
else
echo -e "不存在的ROOT_DIR路径[${ROOT_DIR}]! 请检查脚本配置后重试"
fi
#!/bin/sh
### 项目配置 ####
# 项目名
NAME=OneBlog开源博客
# 项目根目录
BASE_DIR=oneblog
# 根目录
ROOT_PATH=/var/www
# 项目目录
PROJECT_PATH=${ROOT_PATH}/gitee/${BASE_DIR}
# 部署目录
DEPLOY_PATH=${ROOT_PATH}/site/${BASE_DIR}
# 项目远程仓库地址(gitee)
REMOTE_REP_URL=https://gitee.com/yadong.zhang/DBlog
### 打包相关配置 ###
ENV=test
PROFILE_PATH=/src/main/resources/application-${ENV}.yml
BASE_PROFILE_PATH=/src/main/resources/application.yml
####### 颜色代码 ########
## https://www.cnblogs.com/lr-ting/archive/2013/02/28/2936792.html ##
RED="31m" # Error message
GREEN="32m" # Success message
YELLOW="33m" # Warning message
BLUE="36m" # Info message
echoLog(){
color="$1"
echo -e "\033[${color} ${@:2} \033[0m"
}
echoSuccess(){
echoLog ${GREEN} $1
}
echoWarning(){
echoLog ${YELLOW} $1
}
echoInfo(){
echoLog ${BLUE} $1
}
echoError(){
echoLog ${RED} $1
}
useage(){
echo -e "
Copyright @ https://www.zhyd.me . Current Version : v1.0.0
使用方法:
sh oneblog-cli.sh [options] [modules]
[options]
install : 安装
update : 更新
[modules]
web : 前台程序(blog-web)
admin : 后台程序(blog-admin)
示例:
sh oneblog-cli.sh install web
sh oneblog-cli.sh update web
"
echoWarning "注:如果脚本无法执行(报异常),请使用dos2unix命令编译(yum install dos2unix)"
echoWarning "----"
echoWarning "注:本工具不支持一键安装MySQL. 需自行安装MySQL/MariaDB,并创建名为dblog的数据库"
exit 1
}
install(){
# 项目类型: web | admin
PROJECT_TYPE=$1
MODULE_NAME=blog-${PROJECT_TYPE}
echoWarning "注:本工具不支持一键安装MySQL. 需自行安装MySQL/MariaDB,并创建名为dblog的数据库"
installMaven
installJdk
installGit
# installMysql
cloneSourceCode
if [ ! -n "$PROJECT_TYPE" && 'all' != "$PROJECT_TYPE" ] ;then
# 只编译指定模块
config ${PROJECT_TYPE} ${MODULE_NAME}
build ${PROJECT_TYPE} ${MODULE_NAME}
else
# 全部编译
config 'web' 'blog-web'
config 'admin' 'blog-admin'
build 'web' 'blog-web'
build 'admin' 'blog-admin'
fi
echo -e "----------------------------------------------------"
echoSuccess "Congratulations! \n ${NAME} 安装成功..."
echoSuccess "使用systemctl start oneblog-[web|admin]启动"
echoSuccess "使用systemctl enable oneblog-[web|admin]将oneblog-[web|admin]加入开机启动"
echo -e "----------------------------------------------------"
}
installMaven(){
read -p '是否安装maven?[y/n]' maven
if [ "${maven}" = "y" -o "${maven}" = "Y" ];then
wget http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo
yum install -y -q apache-maven
echoSuccess "Maven安装完成,版本为: `mvn --version | head -1`"
fi
}
installJdk(){
read -p '是否安装OpenJDK1.8?[y/n]' jdk
if [ "${jdk}" = "y" -o "${jdk}" = "Y" ];then
yum install -y -q java-1.8.0-openjdk java-1.8.0-openjdk-devel
echoSuccess "OpenJDK安装完成,版本为: `java -version | head -1`"
fi
}
installGit(){
read -p '是否安装Git?[y/n]' git
if [ "${git}" = "y" -o "${git}" = "Y" ];then
yum install -y -q git
echoSuccess "Git安装完成,版本为: `git --version | head -1`"
fi
}
cloneSourceCode(){
if [[ -d ${PROJECT_PATH} ]]; then
rm -rf ${PROJECT_PATH}
fi
echo -e "----------------------------------------------------"
echoInfo "正在下载${NAME}..."
echo -e "----------------------------------------------------"
git clone ${REMOTE_REP_URL} ${PROJECT_PATH}
}
installMysql(){
rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
yum repolist enabled | grep "mysql.*"
yum -y install mysql-community-server
echoSuccess "MySQL版本为: `mysql -V | head -1`"
}
config() {
PROJECT_TYPE=$1
MODULE_NAME=$2
echoInfo "开始配置 ${MODULE_NAME}"
cd ${PROJECT_PATH}
# 配置redis
read -p 'Redis的密码(无密码请直接回车):' -s redisPassword
if [ -n "${redisPassword}" ]; then
sed -i "72s/: /${redisPassword}/" ${PROJECT_PATH}/${MODULE_NAME}${BASE_PROFILE_PATH}
else
sed -i '72s/^[^#]/#&/' ${PROJECT_PATH}/${MODULE_NAME}${BASE_PROFILE_PATH}
fi
echo -e "\n"
# 配置mysql
read -p 'Mysql的用户名:' username
read -p 'Mysql的密码:' -s password
sed -i "11s/root/${username}/" ${PROJECT_PATH}/${MODULE_NAME}${PROFILE_PATH}
sed -i "12s/root/${password}/" ${PROJECT_PATH}/${MODULE_NAME}${PROFILE_PATH}
echo -e "\n"
# 配置mail
read -p '是否配置mail?[y/n]' mail
if [ "${mail}" = "y" -o "${mail}" = "Y" ];then
read -p 'host:' mailHost
read -p 'username:' mailUsername
read -p 'password:' -s mailPassword
sed -i "19s/xxx/${mailHost}/" ${PROJECT_PATH}/${MODULE_NAME}${PROFILE_PATH}
sed -i "22s/xxx/${mailUsername}/" ${PROJECT_PATH}/${MODULE_NAME}${PROFILE_PATH}
sed -i "24s/xxx/${mailPassword}/" ${PROJECT_PATH}/${MODULE_NAME}${PROFILE_PATH}
echo -e "\n"
fi
# 配置验证码
read -p '是否启用验证码?[y/n]' kaptcha
if [ "${kaptcha}" = "y" -o "${kaptcha}" = "Y" ];then
sed -i "44s/false/true/" ${PROJECT_PATH}/${MODULE_NAME}${PROFILE_PATH}
fi
echoInfo "${MODULE_NAME} 配置完成 >> "
echoInfo "----------------------------------------------------"
}
build(){
PROJECT_TYPE=$1
MODULE_NAME=$2
echo -e "----------------------------------------------------"
echoInfo "开始打包${MODULE_NAME}..."
cd ${PROJECT_PATH}
sh ${PROJECT_PATH}/build.sh ${ENV}
STATUS=$?
if [[ $STATUS == 0 ]]; then
echoSuccess "${MODULE_NAME}打包成功..."
mkdir -p ${DEPLOY_PATH}/${PROJECT_TYPE}
cp -R ${MODULE_NAME}/target/${MODULE_NAME}.jar ${DEPLOY_PATH}/${PROJECT_TYPE}
touch /etc/systemd/system/oneblog-${PROJECT_TYPE}.service
cat > /etc/systemd/system/oneblog-${PROJECT_TYPE}.service << EOF
[Unit]
Description=oneblog-${PROJECT_TYPE}
After=network.target
Wants=network.target
[Service]
Type=simple
ExecStart=/usr/bin/java -server -Xms256m -Xmx512m -jar ${DEPLOY_PATH}/${PROJECT_TYPE}/blog-${PROJECT_TYPE}.jar > ${DEPLOY_PATH}/${PROJECT_TYPE}/blog-${PROJECT_TYPE}.log
ExecStop=/bin/kill -s QUIT $MAINPID
Restart=always
StandOutput=syslog
StandError=inherit
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
else
echoError "${MODULE_NAME}打包失败"
exit 1
fi
echo -e "----------------------------------------------------"
}
if [[ $# > 0 ]]; then
module="all"
if [ -n $2 ] ;then
module=$2
fi
case $1 in
"install")
install ${module}
;;
"update")
update ${module}
;;
*)
useage
;;
esac
else
useage
fi
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册