我正在尝试将服务器服务部署到AWS EC2实例。这项服务基本上是永远运行的消费者。
要在AWS上部署,似乎我需要指定以下文件:
我在编写applicationStart和applicationStop脚本时遇到麻烦。
我的程序是一个Java jar文件,我使用java -jar consumer.jar
执行了它。因此,起初我编写了applicationStart和applicationStop,如下所示:
ApplicationStart:
java -jar consumer.jar
ApplicationStop:
exit 0
这是appspec文件的片段
hooks:
ApplicationStop:
- location: script/deploy/stop-application.sh
timeout: 30
runas: root
BeforeInstall:
- location: script/deploy/before-install.sh
timeout: 30
runas: root
AfterInstall:
- location: script/deploy/after-install.sh
timeout: 30
runas: services
ApplicationStart:
- location: script/deploy/start-application.sh
timeout: 30
runas: root
ValidateService:
- location: script/deploy/validate-application.sh
timeout: 30
runas: root
当我将代码部署到AWS时,我发现Java程序保持运行,并且applicationStart阶段最终超时。我认为这可能是因为Java程序不会返回,因此applicationStart根本无法完成。因此,我将startApplication(或脚本start-application.sh)更改为这样
nohup java -jar consumer.jar &
这一次,startApplication阶段没有超时。相反,它需要3分钟才能成功。考虑到我的超时时间设置为30秒,为什么不超时呢?并且部署处于AllowTraffic
阶段,最终花费了1个小时超时。
关于程序永久运行时如何编写applicationStart和applicationStop脚本的任何建议?任何建议将不胜感激!
答案 0 :(得分:0)
我想我终于找到答案了。基本上,我们需要在命令末尾添加library(shiny)
library(shinyjs)
library(tidyverse)
library(DT) #load after shiny
data_input <- data.frame(ID=seq(1,50),
weight=sample(50:65,50,replace = TRUE),
height=sample(150:225,50,replace = TRUE)
)
#shiny---
shinyApp(
#ui----
ui= fluidPage(
fluidRow(
br(),
column(2,
actionButton("increase_weight","increase weight"),
uiOutput("show_row_selected")
),
column(4,DT::DTOutput("data_table"))
)
),
server=function(input,output,session){
#save data frame as a reactive value
RV <- reactiveValues(
data=data_input
)
previousSelection <- NULL
previousPage <- NULL
#render data table
output$data_table <- DT::renderDataTable({
DT::datatable(
RV$data,
editable = TRUE,
selection = list(mode = "single", target = "row", selected = previousSelection),
options = list(
autoWidth=TRUE,
scrollX = TRUE,
pageLength = 10,
displayStart = previousPage))
})
#edit a single cell----
observeEvent(input$data_table_cell_edit, {
info <- input$data_table_cell_edit
edit_row <- info$row
edit_col <- info$col
edit_value <- info$value
previousSelection <<- input$data_table_rows_selected
previousPage <<- input$data_table_rows_current[1] - 1
#find leg to be edited
RV$data[edit_row,edit_col] <-as.numeric(edit_value)
})
#increase weight by one----
observeEvent(input$increase_weight, {
edit_row <- input$data_table_rows_selected
previousSelection <<- input$data_table_rows_selected
previousPage <<- input$data_table_rows_current[1] - 1
RV$data[edit_row,"weight"] <- RV$data[edit_row,"weight"]+1
})
#show current row selected----
output$show_row_selected <- renderText({
paste0("row selected: ",as.character(as.numeric(input$data_table_rows_selected)))
})
})
,以指示AWS忽略所有stderr和stdout。这样,该过程将不会阻止部署。
请参阅参考文献,例如: