diff --git a/Linux服务器监听运维功能.md b/Linux服务器监听运维功能.md index 0f7703d..d63ac59 100644 --- a/Linux服务器监听运维功能.md +++ b/Linux服务器监听运维功能.md @@ -147,10 +147,10 @@ ## 1.5 配置启动服务 ### 1.5.1 创建 -| 调用方式 | 接口地址 | -| ------------ | :------------------------------------------------------ | -| POST | http://ip:port/occupationOfBasicResources/createService | -| Content-Type | application/json;charset=UTF-8 | +| 调用方式 | 接口地址 | +| ------------ | :-------------------------------------- | +| POST | http://ip:port/background/createService | +| Content-Type | application/json;charset=UTF-8 | | 请求参数 | | | | | | ----------- | ------------ | ------- | ---- | -------------- | @@ -192,10 +192,10 @@ ### 1.5.2 更新 -| 调用方式 | 接口地址 | -| ------------ | :------------------------------------------------------ | -| POST | http://ip:port/occupationOfBasicResources/updateService | -| Content-Type | application/json;charset=UTF-8 | +| 调用方式 | 接口地址 | +| ------------ | :-------------------------------------- | +| POST | http://ip:port/background/updateService | +| Content-Type | application/json;charset=UTF-8 | | 请求参数 | | | | | | ----------- | ------------ | ------- | ---- | -------------- | @@ -239,10 +239,10 @@ ### 1.5.3 删除 -| 调用方式 | 接口地址 | -| ------------ | :------------------------------------------------------ | -| POST | http://ip:port/occupationOfBasicResources/deleteService | -| Content-Type | application/json;charset=UTF-8 | +| 调用方式 | 接口地址 | +| ------------ | :-------------------------------------- | +| POST | http://ip:port/background/deleteService | +| Content-Type | application/json;charset=UTF-8 | | 请求参数 | | | | | | -------- | -------- | ------- | ---- | ------------------ | @@ -269,12 +269,49 @@ } ``` + +### 1.5.4 操作已经配置好的服务 + +| 调用方式 | 接口地址 | +| ------------ | :-------------------------------------- | +| POST | http://ip:port/background/serviceAction | +| Content-Type | application/json;charset=UTF-8 | + +| 请求参数 | | | | | +| -------- | -------- | ------- | ---- | --------------------------------------------------- | +| 参数项 | 名称 | 类型 | 必选 | 描述 | +| id | 服务主键 | Integer | 是 | 主键(formdata形式) | +| action | 操作类型 | String | 是 | start/status/restart/stop/remove/load(formdata形式) | +``` +请求示例 +"id": 1 +"action": "start" +``` + +| 返回结果 | | | | +| -------- | -------- | ------ | --------------------------------- | +| 参数项 | 名称 | 类型 | 描述 | +| code | 响应码 | int | 200为操作成功,其他code表示失败 | +| message | 提示信息 | string | 200为操作成功, 其他为对应错误信息 | +| data | 返回信息 | | | +| result | 操作结果 | string | 操作成功或者失败原因 | + +``` +响应示例 +{ + "code": 200, + "message": "操作成功", + "data": {} +} +``` + + ## 1.6 查询配置好的服务运行情况 -| 调用方式 | 接口地址 | -| ------------ | :----------------------------------------------------- | -| POST | http://ip:port/occupationOfBasicResources/serviceQuery | -| Content-Type | application/json;charset=UTF-8 | +| 调用方式 | 接口地址 | +| ------------ | :------------------------------------- | +| POST | http://ip:port/background/serviceQuery | +| Content-Type | application/json;charset=UTF-8 | | 请求参数 | | | | | | ----------- | -------- | ------- | ---- | ---------------------- | diff --git a/src/main/java/com/objecteye/common/GeneralContent.java b/src/main/java/com/objecteye/common/GeneralContent.java index 1607cd2..01a6215 100644 --- a/src/main/java/com/objecteye/common/GeneralContent.java +++ b/src/main/java/com/objecteye/common/GeneralContent.java @@ -17,9 +17,21 @@ public class GeneralContent { */ public final static String REDIS_RECORD_MODULE = "redisRecordModule"; /** + * 服务对应docker镜像id + */ + public final static String REDIS_SERVICE_DOCKER_CONTAINER_ID = "redisServiceDockerContainerId"; + /** + * 服务对应docker启动状态 + */ + public final static String REDIS_SERVICE_DOCKER_STATUS = "redisServiceDockerStatus"; + /** * sh功能脚本map */ public final static Map MODULE_MAP = new HashMap<>(); + /** + * docker启动脚本输出对应中文 + */ + public final static Map DOCKER_SH_OUT_MAP = new HashMap<>(); static { MODULE_MAP.put("arp_cache", "/shell_files/arp_cache.sh"); @@ -54,5 +66,19 @@ public class GeneralContent { MODULE_MAP.put("swap", "/shell_files/swap.sh"); MODULE_MAP.put("upload_transfer_rate", "/shell_files/upload_transfer_rate.sh"); MODULE_MAP.put("user_accounts", "/shell_files/user_accounts.sh"); + MODULE_MAP.put("sysv", "/shell_files/sysv.sh"); + + DOCKER_SH_OUT_MAP.put("0", "成功"); + DOCKER_SH_OUT_MAP.put("1", "失败"); + DOCKER_SH_OUT_MAP.put("2", "端口参数为空"); + DOCKER_SH_OUT_MAP.put("3", "端口类型错误"); + DOCKER_SH_OUT_MAP.put("4", "服务未启动"); + DOCKER_SH_OUT_MAP.put("5", "容器启动失败"); + DOCKER_SH_OUT_MAP.put("6", "本地镜像不存在"); + DOCKER_SH_OUT_MAP.put("7", "容器参数为空"); + DOCKER_SH_OUT_MAP.put("8", "方法参数错误"); + DOCKER_SH_OUT_MAP.put("9", "容器不存在"); + DOCKER_SH_OUT_MAP.put("10", "端口已经被占用"); + DOCKER_SH_OUT_MAP.put("11", "未知错误"); } } diff --git a/src/main/java/com/objecteye/controller/BackGroundController.java b/src/main/java/com/objecteye/controller/BackGroundController.java index 4a1a1b4..6db864e 100644 --- a/src/main/java/com/objecteye/controller/BackGroundController.java +++ b/src/main/java/com/objecteye/controller/BackGroundController.java @@ -77,4 +77,10 @@ public class BackGroundController extends BasicController { public CommonResult serviceQuery(@RequestParam Integer currentPage, @RequestParam Integer pageVolume) { return pageResultHandle(iBackGroundService.serviceQuery(currentPage, pageVolume)); } + + @ApiOperation("操作已经配置好的服务") + @RequestMapping(value = "serviceAction", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) + public CommonResult serviceAction(@RequestParam(required = false) Integer id, @RequestParam(required = false) String action) { + return jsonObjectResultHandle(iBackGroundService.serviceAction(id, action)); + } } diff --git a/src/main/java/com/objecteye/service/IBackGroundService.java b/src/main/java/com/objecteye/service/IBackGroundService.java index b5e5c9b..5aa7057 100644 --- a/src/main/java/com/objecteye/service/IBackGroundService.java +++ b/src/main/java/com/objecteye/service/IBackGroundService.java @@ -90,4 +90,13 @@ public interface IBackGroundService { * @return 结果集 */ PageResult serviceQuery(Integer currentPage, Integer pageVolume); + + /** + * 操作服务 + * + * @param configId 服务配置主键 + * @param action 操作 + * @return 操作状态 + */ + JSONObject serviceAction(Integer configId, String action); } diff --git a/src/main/java/com/objecteye/service/IOccupationOfBasicResourcesService.java b/src/main/java/com/objecteye/service/IOccupationOfBasicResourcesService.java index ec2ad28..2b47f95 100644 --- a/src/main/java/com/objecteye/service/IOccupationOfBasicResourcesService.java +++ b/src/main/java/com/objecteye/service/IOccupationOfBasicResourcesService.java @@ -19,6 +19,14 @@ public interface IOccupationOfBasicResourcesService { JSONArray getInfoByModule(Map requestMap); /** + * 获取指定module的输出 + * + * @param module 请求参数 + * @return 输出结果 + */ + JSONArray getInfoByModule(String module); + + /** * jar包发布 * * @param requestMap 请求参数 diff --git a/src/main/java/com/objecteye/service/impl/BackGroundServiceImpl.java b/src/main/java/com/objecteye/service/impl/BackGroundServiceImpl.java index 8c51ed6..34c12ad 100644 --- a/src/main/java/com/objecteye/service/impl/BackGroundServiceImpl.java +++ b/src/main/java/com/objecteye/service/impl/BackGroundServiceImpl.java @@ -17,10 +17,12 @@ import com.objecteye.vo.VSyServiceMainTable; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.http.ResponseEntity; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.client.RestTemplate; import java.util.*; import java.util.stream.Collectors; @@ -38,6 +40,8 @@ public class BackGroundServiceImpl implements IBackGroundService { private SyServiceConfigMapper syServiceConfigMapper; @Autowired private SyServiceConfigItemMapper syServiceConfigItemMapper; + @Autowired + private RestTemplate restTemplate; /** * 定时写入的定制信息 @@ -45,7 +49,7 @@ public class BackGroundServiceImpl implements IBackGroundService { @Override @Scheduled(fixedRate = 3 * 1000) public void jobController() { - /*String moduleStr = (String) redisTemplate.opsForValue().get(GeneralContent.REDIS_RECORD_MODULE); + String moduleStr = (String) redisTemplate.opsForValue().get(GeneralContent.REDIS_RECORD_MODULE); if (moduleStr == null || "".equals(moduleStr)) { return; } @@ -66,7 +70,7 @@ public class BackGroundServiceImpl implements IBackGroundService { doGpuUtilization(); break; } - }*/ + } } /** @@ -75,11 +79,11 @@ public class BackGroundServiceImpl implements IBackGroundService { @Override @Scheduled(fixedRate = 1000 * 60) public void removeOverTimeData() { - /*Calendar calendar = Calendar.getInstance(); + Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 1); long lastTime = calendar.getTimeInMillis(); - syBasicResourceHistoryMapper.deleteLteTime(lastTime);*/ + syBasicResourceHistoryMapper.deleteLteTime(lastTime); } /** @@ -224,12 +228,28 @@ public class BackGroundServiceImpl implements IBackGroundService { */ @Override public JSONObject sdkController(Map requestMap) { - String action = (String) requestMap.getOrDefault("action", "start"); - // 参数校验 - // 是否启动车车窗检测 0:关闭 1:开启 + String configId = (String) requestMap.get("configId"); + String uri = "/vehicle/loadConfig"; + String configItemName = "ip,port"; + List syServiceConfigItems = + syServiceConfigItemMapper.selectByExample(SyServiceConfigItemExample.newAndCreateCriteria() + .andConfigIdEqualTo(Integer.valueOf(configId)).andItemNameIn(Arrays.asList(configItemName.split(","))) + .example()); + String ip = null; + String port = null; + for (SyServiceConfigItem syServiceConfigItem : syServiceConfigItems) { + if ("ip".equals(syServiceConfigItem.getItemName())) { + ip = syServiceConfigItem.getItemValue(); + } else if ("port".equals(syServiceConfigItem.getItemName())) { + port = syServiceConfigItem.getItemValue(); + } + } JSONObject resultObj = new JSONObject(); - String params = "action," + - "vehicle_car_win_detect_config," + + if (ip == null || port == null) { + resultObj.put("error", "服务配置缺少ip或端口信息"); + return resultObj; + } + String params = "vehicle_car_win_detect_config," + "vehicle_recg_config," + "vehicle_plate_det_recg_config," + "vehicle_color_config," + @@ -240,17 +260,24 @@ public class BackGroundServiceImpl implements IBackGroundService { "gpuId," + "log," + "vehicle_image_quality_config," + - "vehicle_motor_tricycle_analysis_config,port"; + "vehicle_motor_tricycle_analysis_config,port," + + "vehicle_stain_vp_config"; List errorList = new ArrayList<>(); + Map restRequestMap = new HashMap<>(); for (String param : params.split(",")) { if (!requestMap.containsKey(param)) { errorList.add(param + "参数不能为空"); + } else { + restRequestMap.put(param, (String) requestMap.get(param)); } } if (errorList.size() > 0) { resultObj.put("error", String.join(",", errorList)); return resultObj; } + + ResponseEntity responseEntity = restTemplate.postForEntity(ip + ":" + port + uri, restRequestMap, String.class); + resultObj = JSON.parseObject(responseEntity.getBody()); return resultObj; } @@ -361,6 +388,7 @@ public class BackGroundServiceImpl implements IBackGroundService { List configItems = configIdItemsMap.get(syServiceConfig.getId()); VSyServiceMainTable vSyServiceMainTable = new VSyServiceMainTable(); vSyServiceMainTable.setUpdateTime(DateUtil.format(new Date(syServiceConfig.getUpdateTime()), "yyyy-MM-dd HH:mm:ss")); + vSyServiceMainTable.setConfigId(syServiceConfig.getId()); String ip = null; String port = null; @@ -380,8 +408,131 @@ public class BackGroundServiceImpl implements IBackGroundService { } vSyServiceMainTable.setPort(ip + ":" + port); vSyServiceMainTable.setItems(String.join(",", otherParams)); + vSyServiceMainTable.setStatus((String) redisTemplate.opsForHash().get(GeneralContent.REDIS_SERVICE_DOCKER_STATUS, syServiceConfig.getId())); resultList.add(vSyServiceMainTable); } return new PageResult<>((int) Math.ceil((double) total / pageVolume), resultList); } + + /** + * 操作服务 + * + * @param configId 服务配置主键 + * @param action 操作 + * @return 操作状态 + */ + @Override + public JSONObject serviceAction(Integer configId, String action) { + // 如果有启动状态的容器就直接把启动变为重启操作 + if (redisTemplate.opsForHash().hasKey(GeneralContent.REDIS_SERVICE_DOCKER_CONTAINER_ID, configId) && "start".equals(action)) { + action = "restart"; + } + if ("start".equals(action)) { + return serviceDockerStart(configId); + } else { + return serviceDockerOthers(configId, action); + } + } + + /** + * sysv.sh [stop|restart|status|load] {[containerId]} + * + * @param configId 服务配置主键 + * @param action 操作 + * @return 操作状态 + */ + private JSONObject serviceDockerOthers(Integer configId, String action) { + JSONObject resultObj = new JSONObject(); + String stopStatusAction = "stop,remove"; + String startStatusAction = "load,restart"; + String cmd = System.getProperty("user.dir") + GeneralContent.MODULE_MAP.get("sysv") + " " + action + " "; + String containerId = (String) redisTemplate.opsForHash().get(GeneralContent.REDIS_SERVICE_DOCKER_CONTAINER_ID, configId); + SyServiceConfigItem syServiceConfigItem = syServiceConfigItemMapper.selectOneByExample(SyServiceConfigItemExample.newAndCreateCriteria() + .andConfigIdEqualTo(configId).andItemNameEqualTo("port").example()); + if (containerId == null || "".equals(containerId) || syServiceConfigItem == null) { + resultObj.put("error", "服务配置项为空或没有找到容器id"); + } else { + if ("load".equals(action)) { + cmd += ""; + } else if ("remove".equals(action)) { + cmd += containerId; + } else { + cmd += containerId + " " + syServiceConfigItem.getItemValue(); + } + List outList = new ArrayList<>(); + LinuxUtils.executeLinuxCmd(cmd, outList); + if ("remove".equals(action)) { + redisTemplate.opsForHash().delete(GeneralContent.REDIS_SERVICE_DOCKER_CONTAINER_ID, configId); + } + if (outList.size() == 0) { + resultObj.put("error", "未收到服务器响应"); + } else { + String outStr = String.join("", outList); + String[] outArr = outStr.split(" "); + String resultCode = outArr[outArr.length - 1].trim(); + String resultMsg = GeneralContent.DOCKER_SH_OUT_MAP.get(resultCode); + // 更新状态值 + if (stopStatusAction.contains(action) && "0".equals(resultCode)) { + redisTemplate.opsForHash().put(GeneralContent.REDIS_SERVICE_DOCKER_STATUS, configId, "0"); + } else if (startStatusAction.contains(action) && "0".equals(resultCode)) { + redisTemplate.opsForHash().put(GeneralContent.REDIS_SERVICE_DOCKER_STATUS, configId, "1"); + } else if ("status".equals(action)) { + if ("0".equals(resultCode)) { + redisTemplate.opsForHash().put(GeneralContent.REDIS_SERVICE_DOCKER_STATUS, configId, "0"); + } else { + redisTemplate.opsForHash().put(GeneralContent.REDIS_SERVICE_DOCKER_STATUS, configId, "1"); + } + } + if ("0".equals(resultCode)) { + resultObj.put("result", resultMsg); + } else { + resultObj.put("error", resultMsg); + } + + } + } + return resultObj; + } + + /** + * sysv.sh [start] [port] + * + * @param configId 服务配置id + * @return 结果集 + */ + private JSONObject serviceDockerStart(Integer configId) { + JSONObject resultObj = new JSONObject(); + // 获取port参数 + SyServiceConfigItem syServiceConfigItem = syServiceConfigItemMapper.selectOneByExample(SyServiceConfigItemExample.newAndCreateCriteria() + .andConfigIdEqualTo(configId).andItemNameEqualTo("port").example()); + if (syServiceConfigItem == null) { + resultObj.put("error", "没有找到对应数据"); + } else { + String cmd = System.getProperty("user.dir") + GeneralContent.MODULE_MAP.get("sysv") + " start " + syServiceConfigItem.getItemValue(); + List outList = new ArrayList<>(); + LinuxUtils.executeLinuxCmd(cmd, outList); + if (outList.size() > 0) { + String outStr = String.join("", outList); + String[] outArr = outStr.split(" "); + String resultCode = outArr[2].trim(); + String resultMsg = GeneralContent.DOCKER_SH_OUT_MAP.get(resultCode); + if ("0".equals(resultCode)) { + resultObj.put("containerId", outArr[6].replaceAll(" ", "")); + redisTemplate.opsForHash().put(GeneralContent.REDIS_SERVICE_DOCKER_CONTAINER_ID, configId, outArr[6].replaceAll(" ", "")); + redisTemplate.opsForHash().put(GeneralContent.REDIS_SERVICE_DOCKER_STATUS, configId, "1"); + } else { + redisTemplate.opsForHash().put(GeneralContent.REDIS_SERVICE_DOCKER_STATUS, configId, "0"); + } + if ("0".equals(resultCode)) { + resultObj.put("result", resultMsg); + } else { + resultObj.put("error", resultMsg); + } + + } else { + resultObj.put("error", "没有找到对应数据"); + } + } + return resultObj; + } } diff --git a/src/main/java/com/objecteye/service/impl/OccupationOfBasicResourcesServiceImpl.java b/src/main/java/com/objecteye/service/impl/OccupationOfBasicResourcesServiceImpl.java index 022ad89..ff4e388 100644 --- a/src/main/java/com/objecteye/service/impl/OccupationOfBasicResourcesServiceImpl.java +++ b/src/main/java/com/objecteye/service/impl/OccupationOfBasicResourcesServiceImpl.java @@ -31,7 +31,17 @@ public class OccupationOfBasicResourcesServiceImpl implements IOccupationOfBasic */ @Override public JSONArray getInfoByModule(Map requestMap) { - String module = (String) requestMap.get("module"); + return getInfoByModule((String) requestMap.get("module")); + } + + /** + * 获取指定module的输出 + * + * @param module 请求参数 + * @return 输出结果 + */ + @Override + public JSONArray getInfoByModule(String module) { JSONArray resultArr = new JSONArray(); if (GeneralContent.MODULE_MAP.containsKey(module)) { String cmd = System.getProperty("user.dir") + GeneralContent.MODULE_MAP.get(module); diff --git a/src/main/java/com/objecteye/shell_files/sysv.sh b/src/main/java/com/objecteye/shell_files/sysv.sh new file mode 100644 index 0000000..e56214c --- /dev/null +++ b/src/main/java/com/objecteye/shell_files/sysv.sh @@ -0,0 +1,348 @@ +#!/bin/bash +# +successful=0 #ɹ +failed=1 #ʧ +portIsEmpty=2 #˿ڲΪ +portTypeError=3 #˿ʹ +serverNotRunning=4 #δ +containerNoRunning=5 #ʧ +localImageNotExist=6 #ؾ񲻴 +containerIdIsEmpty=7 #Ϊ +methodParameterError=8 #({start|stop|restart|status|load|remove}) +containerIdNotExist=9 # +portOccupied=10 #˿Ѿռ +defaultError=11 #δ֪ + + +containerServerUp="Up" # +containerServerExited="Exited" #˳ +firstLoad=0 #״μؾ +multipleLoad=1 #μ + +# +serverPackage=micro-vehicle-service-engine-visual-huizhi-v1.0.tar +serverImageName=micro-vehicle-service-engine-visual-huizhi +serverImageVersion=v1.0 +serverImgae=$serverImageName:$serverImageVersion +functionType=$1 + +#жǷ +function isNumber(){ + if [ -n "$(echo $1| sed -n "/^[0-9]\+$/p")" ] + then + return $successful + else + return $portTypeError + fi +} + +#ͨ˿ڲ鿴״̬ +#param port +function checkServerByPort(){ +#echo "port -> $1" +count=`netstat -ntl|awk '{print $4}'| grep $1|wc -l` +#echo "count -> $count" +if [ $count -lt 1 ] +then + return $serverNotRunning +else + return $successful +fi +} + +#鿴 +#param containerId +#param port +function checkContainerServer(){ +containerId=$1 +port=$2 +count=`docker ps -a |grep $containerId | grep $containerServerUp |wc -l` +if [ $count == 1 ] +then + sleep 2s + checkServerByPort $port + serverStatus=" $? " + #echo "serverStatus-> $serverStatus" + if [ $serverStatus == $successful ] + then + return $successful + else + return $serverStatus + fi +else + return $containerNoRunning +fi +} + +#id +#param containerId +function checkContainerId(){ + containerId=$1 + if [ $containerId ] + then + checkId=`docker ps -a | awk '{print $1}' |grep $containerId ` + if [ $checkId = $containerId ] + then + return $successful + else + return $containerIdNotExist + fi + else + return $containerIdIsEmpty + fi +} + +#˿ڲ +#param port +function checkPortParam(){ + port=$1 + if [ $port ] + then + isNumber $port + portParamType=" $? " + if [ $portParamType == $successful ] + then + return $successful + else + return $portParamType + fi + else + return $portIsEmpty + fi +} + + + +# +function deployService(){ + port=$1 + containerId=`docker run --runtime=nvidia -e NVIDIA_VISIBLE_DEVICES=all -e NVIDIA_DRIVER_CAPABILITIES=all --network host --name port-$port --ulimit core=0:0 -v /home/$USER/zksy/:/root/zksy/ -d $serverImgae /bin/bash -c "/software/monitor/vehicleServerEngine-start.sh $port && tail -f /software/monitor/watchdog.out "` + containerId=${containerId:0:12} + #echo "containerId -> $containerId" + checkContainerId $containerId + containerIdStatus=" $? " + if [ $containerIdStatus == $successful ] + then + int=1 + containerServerStatus=$defaultError + while(( $int<=5 )) + do + checkContainerServer $containerId $port + containerServerStatus=" $? " + #echo "containerServerStatus -> $containerServerStatus $int " + if [ $containerServerStatus == $successful ] + then + echo "code $successful containerId $containerId" + return $successful + fi + int=`expr $int + 1` + done + return $containerServerStatus + else + return $containerIdStatus + fi +} + +#Ƿ +# Ƿ״μؾ 0:yes 1no +function checkServerImage(){ +image=`docker images |grep $serverImageName |awk '{print $1":"$2}'|grep $serverImgae` +if [[ -n "$image" && $image = $serverImgae ]] +then + echoResult $successful +else + if [ $1 == $firstLoad ] + then + loadServerPackage + else + echoResult $localImageNotExist + fi +fi +} + +#رؾ +function loadServerPackage(){ + docker import $serverPackage $serverImgae + checkServerImage $multipleLoad +} + +# +function echoResult(){ +result=$1 +echo "code $result" +} + +# +#param port +function start(){ + port=$1 + checkPortParam $port + portParamStatus=" $? " + if [ $portParamStatus == $successful ] + then + checkServerByPort $port + portStatus=" $? " + if [ $portStatus == $serverNotRunning ] + then + deployService $port + deployServiceStatus=" $? " + if [ $deployServiceStatus != $successful ] + then + echoResult $deployServiceStatus + fi + else + echoResult $portOccupied + fi + else + echoResult $portParamStatus + fi +} + +# +#param containerId +#param port +function restart(){ + containerId=$1 + port=$2 + checkContainerId $containerId + containerIdStatus=" $? " + if [ $containerIdStatus == $successful ] + then + checkPortParam $port + portParamStatus=" $? " + if [ $portParamStatus == $successful ] + then + docker restart $containerId + int=1 + containerServerStatus=$defaultError + while(( $int<=5 )) + do + checkContainerServer $containerId $port + containerServerStatus=" $? " + if [ $containerServerStatus == $successful ] + then + break + fi + int=`expr $int + 1` + done + echoResult $containerServerStatus + else + echoResult $portParamStatus + fi + else + echoResult $containerIdStatus + fi +} + +#ͣ +#param containerId +#param port +function stop(){ + containerId=$1 + port=$2 + checkContainerId $containerId + containerIdStatus=" $? " + if [ $containerIdStatus == $successful ] + then + checkPortParam $port + portParamStatus=" $? " + if [ $portParamStatus == $successful ] + then + docker stop $containerId + sleep 5s + count=`docker ps -a |grep $containerId | grep $containerServerExited |wc -l` + if [ $count == 1 ] + then + echoResult $successful + else + echoResult $failed + fi + else + echoResult $portParamStatus + fi + else + echoResult $containerIdStatus + fi +} + +#鿴 +#param containerId +#param port +function status(){ + containerId=$1 + port=$2 + checkContainerId $containerId + containerIdStatus=" $? " + if [ $containerIdStatus == $successful ] + then + checkPortParam $port + portParamStatus=" $? " + if [ $portParamStatus == $successful ] + then + checkContainerServer $containerId $port + containerServerStatus=" $? " + echoResult $containerServerStatus + else + echoResult $portParamStatus + fi + else + echoResult $containerIdStatus + fi +} + +#ɾ +#param containerId +function remove(){ + containerId=$1 + checkContainerId $containerId + containerIdStatus=" $? " + if [ $containerIdStatus == $successful ] + then + docker stop $containerId && docker rm $containerId + sleep 2s + checkContainerId $containerId + containerIdRemoveStatus=" $? " + if [ $containerIdRemoveStatus == $containerIdNotExist ] + then + echoResult $successful + else + echoResult $failed + fi + else + echoResult $containerIdStatus + fi +} + + +case $functionType in + start) + start $2 + ;; + stop) + stop $2 $3 + ;; + restart) + restart $2 $3 + ;; + status) + status $2 $3 + ;; + load) + checkServerImage $firstLoad + ;; + remove) + remove $2 + ;; + *) + echoResult $methodParameterError + +esac + +exit 0 + + + + + + + diff --git a/src/main/java/com/objecteye/vo/VSyServiceMainTable.java b/src/main/java/com/objecteye/vo/VSyServiceMainTable.java index 0dfb5ed..cbc248f 100644 --- a/src/main/java/com/objecteye/vo/VSyServiceMainTable.java +++ b/src/main/java/com/objecteye/vo/VSyServiceMainTable.java @@ -32,4 +32,8 @@ public class VSyServiceMainTable implements Serializable { * 最后更新 */ private String updateTime; + /** + * 配置主键 + */ + private Integer configId; }