@@ -10,6 +10,7 @@ import (
1010 "encoding/json"
1111 "fmt"
1212 "io"
13+ "io/ioutil"
1314 "net/url"
1415 "os"
1516 "os/exec"
@@ -532,26 +533,28 @@ func runLegacyAPMServer(streams *cli.IOStreams, path string) (*process.Info, err
532533 if release .Snapshot () {
533534 version = fmt .Sprintf ("%s-SNAPSHOT" , version )
534535 }
535- // Extract the bundled apm-server binary into the APM_SERVER_PATH
536+ // Extract the bundled apm-server into the APM_SERVER_PATH
536537 if err := installer .Install (context .Background (), spec , version , path ); err != nil {
537538 return nil , errors .New (err ,
538539 fmt .Sprintf ("installing %s (%s) from %s to %s" , spec .Name , version , cfg .TargetDirectory , path ))
539540 }
540-
541- // Start apm-server process respecting args
542- logInfo (streams , "Starting legacy apm-server daemon as a subprocess." )
543- pattern := filepath .Join (path , fmt .Sprintf ("%s-%s-%s*" , spec .Cmd , version , cfg .OS ()), spec .Cmd )
544- files , err := filepath .Glob (pattern )
541+ // Get the apm-server directory
542+ files , err := ioutil .ReadDir (path )
545543 if err != nil {
546- return nil , errors .New (err , fmt .Sprintf ("searching apm-server in %s" , pattern ))
544+ return nil , errors .New (err , fmt .Sprintf ("reading directory %s" , path ))
547545 }
548- if len (files ) != 1 {
549- return nil , errors .New ("multiple apm-server versions installed " )
546+ if len (files ) != 1 || ! files [ 0 ]. IsDir () {
547+ return nil , errors .New ("expected one directory " )
550548 }
551- f , err := filepath .Abs (files [0 ])
552- if err != nil {
553- return nil , errors .New (err , fmt .Sprintf ("absPath for %s" , files [0 ]))
549+ apmDir := filepath .Join (path , files [0 ].Name ())
550+ // Extract the ingest pipeline definition to the HOME_DIR
551+ if home := os .Getenv ("HOME_PATH" ); home != "" {
552+ if err := syncDir (filepath .Join (apmDir , "ingest" ), filepath .Join (home , "ingest" )); err != nil {
553+ return nil , fmt .Errorf ("syncing APM ingest directory to HOME_PATH(%s) failed: %s" , home , err )
554+ }
554555 }
556+ // Start apm-server process respecting path ENVs
557+ apmBinary := filepath .Join (apmDir , spec .Cmd )
555558 log , err := logger .New ("apm-server" , false )
556559 if err != nil {
557560 return nil , err
@@ -568,7 +571,8 @@ func runLegacyAPMServer(streams *cli.IOStreams, path string) (*process.Info, err
568571 addEnv ("--path.data" , "DATA_PATH" )
569572 addEnv ("--path.logs" , "LOGS_PATH" )
570573 addEnv ("--httpprof" , "HTTPPROF" )
571- return process .Start (log , f , nil , os .Geteuid (), os .Getegid (), args ... )
574+ logInfo (streams , "Starting legacy apm-server daemon as a subprocess." )
575+ return process .Start (log , apmBinary , nil , os .Geteuid (), os .Getegid (), args ... )
572576}
573577
574578func logToStderr (cfg * configuration.Configuration ) {
@@ -602,7 +606,9 @@ func setPaths() error {
602606 }
603607 }
604608 // sync the downloads to the data directory
605- if err := syncDownloads (statePath ); err != nil {
609+ srcDownloads := filepath .Join (paths .Home (), "downloads" )
610+ destDownloads := filepath .Join (statePath , "data" , "downloads" )
611+ if err := syncDir (srcDownloads , destDownloads ); err != nil {
606612 return fmt .Errorf ("syncing download directory to STATE_PATH(%s) failed: %s" , statePath , err )
607613 }
608614 paths .SetTop (topPath )
@@ -620,22 +626,20 @@ func setPaths() error {
620626 return nil
621627}
622628
623- func syncDownloads (dataPath string ) error {
624- srcDownloads := filepath .Join (paths .Home (), "downloads" )
625- destDownloads := filepath .Join (dataPath , "data" , "downloads" )
626- return filepath .Walk (srcDownloads , func (path string , info os.FileInfo , err error ) error {
629+ func syncDir (src string , dest string ) error {
630+ return filepath .Walk (src , func (path string , info os.FileInfo , err error ) error {
627631 if err != nil {
628632 return err
629633 }
630- relativePath := strings .TrimPrefix (path , srcDownloads )
634+ relativePath := strings .TrimPrefix (path , src )
631635 if info .IsDir () {
632- err = os .MkdirAll (filepath .Join (destDownloads , relativePath ), info .Mode ())
636+ err = os .MkdirAll (filepath .Join (dest , relativePath ), info .Mode ())
633637 if err != nil {
634638 return err
635639 }
636640 return nil
637641 }
638- return copyFile (filepath .Join (destDownloads , relativePath ), path , info .Mode ())
642+ return copyFile (filepath .Join (dest , relativePath ), path , info .Mode ())
639643 })
640644}
641645
0 commit comments