From 38f04aa9f8ab2d0ac435c10384eefc9cd2e5e2e5 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sat, 22 Jul 2023 22:15:24 +0400 Subject: [PATCH] Removed code for liquidsoap. --- cmd/dwelling-radio/main.go | 17 +------- configs/config.test.yaml | 3 -- configs/config.yaml | 3 -- init/radio.service | 2 +- internal/configuration/configuration.go | 6 +-- internal/radio/liquidsoap.go | 54 ------------------------- 6 files changed, 3 insertions(+), 82 deletions(-) delete mode 100644 internal/radio/liquidsoap.go diff --git a/cmd/dwelling-radio/main.go b/cmd/dwelling-radio/main.go index a2ef641..56ae549 100644 --- a/cmd/dwelling-radio/main.go +++ b/cmd/dwelling-radio/main.go @@ -5,7 +5,6 @@ import ( "dwelling-radio/internal/http" "dwelling-radio/internal/radio" "dwelling-radio/web" - "errors" "flag" "fmt" "io/fs" @@ -19,8 +18,7 @@ import ( ) var ( - configPath *string = flag.String("conf", "config.yaml", "path to configuration file") - noLiquidsoap *bool = flag.Bool("no-liquidsoap", false, "don't run liquidsoap") + configPath *string = flag.String("conf", "config.yaml", "path to configuration file") showVersion *bool = flag.Bool("v", false, "show version") ) @@ -53,19 +51,6 @@ func main() { } defer playlistWatcher.Close() - if !*noLiquidsoap { - liquid, err := radio.NewLiquidsoap(config.Liquidsoap.ExecPath, config.Liquidsoap.ScriptPath) - if err != nil { - log.Fatalln("liquidsoap:", err) - } - - defer func() { - if err := liquid.Stop(); err != nil && !errors.Is(err, radio.ErrLiquidsoapNotRunning) { - log.Println(err) - } - }() - } - hand := http.NewHandlers(config) r := httpr.New() diff --git a/configs/config.test.yaml b/configs/config.test.yaml index 6b05265..ba85153 100644 --- a/configs/config.test.yaml +++ b/configs/config.test.yaml @@ -8,8 +8,5 @@ icecast: playlist_path: "playlist.log" filelist_path: "/srv/radio/filelist.html" most_listened_song_file_path: "/mnt/data/appdata/mostlistenedsong" -liquidsoap: - executable_path: "/opt/opam/4.14.0/bin/liquidsoap" - script_path: "/etc/dwelling/radio.liq" # How much songs to list on a page list_last_n_songs: 10 \ No newline at end of file diff --git a/configs/config.yaml b/configs/config.yaml index cd0e5f3..e51728f 100644 --- a/configs/config.yaml +++ b/configs/config.yaml @@ -8,8 +8,5 @@ icecast: playlist_path: "/var/log/icecast/playlist.log" filelist_path: "/srv/radio/filelist.html" most_listened_song_file_path: "/mnt/data/appdata/mostlistenedsong" -liquidsoap: - executable_path: "/opt/opam/4.14.0/bin/liquidsoap" - script_path: "/etc/dwelling/radio.liq" # How much songs to list on a page list_last_n_songs: 10 \ No newline at end of file diff --git a/init/radio.service b/init/radio.service index 0edfa00..1759142 100755 --- a/init/radio.service +++ b/init/radio.service @@ -7,7 +7,7 @@ After=network-online.target icecast.service Type=simple Restart=on-failure DynamicUser=yes -ExecStart=/usr/bin/dwelling-radio -no-liquidsoap -conf /etc/dwelling/radio.yaml +ExecStart=/usr/bin/dwelling-radio -conf /etc/dwelling/radio.yaml ReadOnlyPaths=/ diff --git a/internal/configuration/configuration.go b/internal/configuration/configuration.go index edd5d02..5e51eb4 100644 --- a/internal/configuration/configuration.go +++ b/internal/configuration/configuration.go @@ -16,11 +16,7 @@ type Configuration struct { } `yaml:"icecast"` FilelistPath string `yaml:"filelist_path"` MostListenedSongPath string `yaml:"most_listened_song_file_path"` - Liquidsoap struct { - ExecPath string `yaml:"executable_path"` - ScriptPath string `yaml:"script_path"` - } `yaml:"liquidsoap"` - ListLastNSongs int `yaml:"list_last_n_songs"` + ListLastNSongs int `yaml:"list_last_n_songs"` } // Load reads a YAML file that stores configuration of a service. diff --git a/internal/radio/liquidsoap.go b/internal/radio/liquidsoap.go deleted file mode 100644 index 4417e3b..0000000 --- a/internal/radio/liquidsoap.go +++ /dev/null @@ -1,54 +0,0 @@ -package radio - -import ( - "os/exec" - "syscall" - - "github.com/pkg/errors" -) - -var ErrLiquidsoapNotRunning = errors.New("liquidsoap is not running") - -type Liquidsoap struct { - command *exec.Cmd -} - -func NewLiquidsoap(liquidsoapPath, scriptPath string) (*Liquidsoap, error) { - if _, err := exec.LookPath(liquidsoapPath); err != nil { - return nil, err - } - - out, err := exec.Command(liquidsoapPath, "--verbose", "-c", scriptPath).CombinedOutput() - if err != nil { - return nil, errors.Wrap(err, "script cannot be validated") - } - - if len(out) > 0 { - return nil, errors.Errorf("script validation failed: %s", string(out)) - } - - cmd := exec.Command(liquidsoapPath, scriptPath) - - if err := cmd.Start(); err != nil { - return nil, err - } - - return &Liquidsoap{ - command: cmd}, nil -} - -func (l *Liquidsoap) Stop() error { - if l.command.Process == nil && l.command.ProcessState != nil { - return ErrLiquidsoapNotRunning - } - - if err := l.command.Process.Signal(syscall.SIGINT); err != nil { - return err - } - - if err := l.command.Wait(); err != nil { - return err - } - - return nil -}