1
0

Removed code for liquidsoap.

This commit is contained in:
Alexander Andreev 2023-07-22 22:15:24 +04:00
parent 4512e6aa53
commit 38f04aa9f8
Signed by: Arav
GPG Key ID: D22A817D95815393
6 changed files with 3 additions and 82 deletions

View File

@ -5,7 +5,6 @@ import (
"dwelling-radio/internal/http" "dwelling-radio/internal/http"
"dwelling-radio/internal/radio" "dwelling-radio/internal/radio"
"dwelling-radio/web" "dwelling-radio/web"
"errors"
"flag" "flag"
"fmt" "fmt"
"io/fs" "io/fs"
@ -19,8 +18,7 @@ import (
) )
var ( var (
configPath *string = flag.String("conf", "config.yaml", "path to configuration file") configPath *string = flag.String("conf", "config.yaml", "path to configuration file")
noLiquidsoap *bool = flag.Bool("no-liquidsoap", false, "don't run liquidsoap")
showVersion *bool = flag.Bool("v", false, "show version") showVersion *bool = flag.Bool("v", false, "show version")
) )
@ -53,19 +51,6 @@ func main() {
} }
defer playlistWatcher.Close() 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) hand := http.NewHandlers(config)
r := httpr.New() r := httpr.New()

View File

@ -8,8 +8,5 @@ icecast:
playlist_path: "playlist.log" playlist_path: "playlist.log"
filelist_path: "/srv/radio/filelist.html" filelist_path: "/srv/radio/filelist.html"
most_listened_song_file_path: "/mnt/data/appdata/mostlistenedsong" 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 # How much songs to list on a page
list_last_n_songs: 10 list_last_n_songs: 10

View File

@ -8,8 +8,5 @@ icecast:
playlist_path: "/var/log/icecast/playlist.log" playlist_path: "/var/log/icecast/playlist.log"
filelist_path: "/srv/radio/filelist.html" filelist_path: "/srv/radio/filelist.html"
most_listened_song_file_path: "/mnt/data/appdata/mostlistenedsong" 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 # How much songs to list on a page
list_last_n_songs: 10 list_last_n_songs: 10

View File

@ -7,7 +7,7 @@ After=network-online.target icecast.service
Type=simple Type=simple
Restart=on-failure Restart=on-failure
DynamicUser=yes 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=/ ReadOnlyPaths=/

View File

@ -16,11 +16,7 @@ type Configuration struct {
} `yaml:"icecast"` } `yaml:"icecast"`
FilelistPath string `yaml:"filelist_path"` FilelistPath string `yaml:"filelist_path"`
MostListenedSongPath string `yaml:"most_listened_song_file_path"` MostListenedSongPath string `yaml:"most_listened_song_file_path"`
Liquidsoap struct { ListLastNSongs int `yaml:"list_last_n_songs"`
ExecPath string `yaml:"executable_path"`
ScriptPath string `yaml:"script_path"`
} `yaml:"liquidsoap"`
ListLastNSongs int `yaml:"list_last_n_songs"`
} }
// Load reads a YAML file that stores configuration of a service. // Load reads a YAML file that stores configuration of a service.

View File

@ -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
}