feature: Adds autostart support.
This commit is contained in:
parent
8ba0424512
commit
5c45533371
6 changed files with 46 additions and 8 deletions
|
@ -105,7 +105,7 @@ func LookupBackend(c *gin.Context) {
|
|||
}
|
||||
|
||||
if req.Backend != nil {
|
||||
queryString = append(queryString, "isbot = ?")
|
||||
queryString = append(queryString, "is_bot = ?")
|
||||
queryParameters = append(queryParameters, req.Backend)
|
||||
}
|
||||
|
||||
|
|
|
@ -124,22 +124,22 @@ func LookupProxy(c *gin.Context) {
|
|||
}
|
||||
|
||||
if req.SourcePort != nil {
|
||||
queryString = append(queryString, "sourceport = ?")
|
||||
queryString = append(queryString, "source_port = ?")
|
||||
queryParameters = append(queryParameters, req.SourcePort)
|
||||
}
|
||||
|
||||
if req.DestinationPort != nil {
|
||||
queryString = append(queryString, "destinationport = ?")
|
||||
queryString = append(queryString, "destination_port = ?")
|
||||
queryParameters = append(queryParameters, req.DestinationPort)
|
||||
}
|
||||
|
||||
if req.ProviderID != nil {
|
||||
queryString = append(queryString, "backendid = ?")
|
||||
queryString = append(queryString, "backend_id = ?")
|
||||
queryParameters = append(queryParameters, req.ProviderID)
|
||||
}
|
||||
|
||||
if req.AutoStart != nil {
|
||||
queryString = append(queryString, "autostart = ?")
|
||||
queryString = append(queryString, "auto_start = ?")
|
||||
queryParameters = append(queryParameters, req.AutoStart)
|
||||
}
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ func LookupUser(c *gin.Context) {
|
|||
}
|
||||
|
||||
if req.IsBot != nil {
|
||||
queryString = append(queryString, "isbot = ?")
|
||||
queryString = append(queryString, "is_bot = ?")
|
||||
queryParameters = append(queryParameters, req.IsBot)
|
||||
}
|
||||
|
||||
|
|
|
@ -152,6 +152,43 @@ func entrypoint(cCtx *cli.Context) error {
|
|||
}
|
||||
|
||||
backendruntime.RunningBackends[backend.ID] = backendInstance
|
||||
|
||||
log.Infof("Successfully initialized backend #%d", backend.ID)
|
||||
|
||||
autoStartProxies := []dbcore.Proxy{}
|
||||
|
||||
if err := dbcore.DB.Where("backend_id = ? AND auto_start = true", backend.ID).Find(&autoStartProxies).Error; err != nil {
|
||||
log.Errorf("Failed to query proxies to autostart: %s", err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
for _, proxy := range autoStartProxies {
|
||||
log.Infof("Starting up route #%d for backend #%d: %s", proxy.ID, backend.ID, proxy.Name)
|
||||
|
||||
backendInstance.RuntimeCommands <- &commonbackend.AddProxy{
|
||||
Type: "addProxy",
|
||||
SourceIP: proxy.SourceIP,
|
||||
SourcePort: proxy.SourcePort,
|
||||
DestPort: proxy.DestinationPort,
|
||||
Protocol: proxy.Protocol,
|
||||
}
|
||||
|
||||
backendResponse := <-backendInstance.RuntimeCommands
|
||||
|
||||
switch responseMessage := backendResponse.(type) {
|
||||
case error:
|
||||
log.Errorf("Failed to get response for backend #%d and route #%d: %s", proxy.BackendID, proxy.ID, responseMessage.Error())
|
||||
continue
|
||||
case *commonbackend.ProxyStatusResponse:
|
||||
if !responseMessage.IsActive {
|
||||
log.Warnf("Failed to start proxy for backend #%d and route #%d", proxy.BackendID, proxy.ID)
|
||||
}
|
||||
default:
|
||||
log.Errorf("Got illegal response type for backend #%d and proxy #%d: %T", proxy.BackendID, proxy.ID, responseMessage)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
log.Infof("Successfully started backend #%d", backend.ID)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue