Last active
January 19, 2020 16:10
-
-
Save ykpythemind/b1b1ae2796acb6df160ec745b7ad2d21 to your computer and use it in GitHub Desktop.
shairport sync up
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
def shairport! | |
system "shairport-sync -d" | |
end | |
pidfile = "/usr/local/var/run/shairport-sync.pid" | |
if File.exist?(pidfile) | |
pid = File.read(pidfile).chomp | |
processes = `ps aux`.split("\n") | |
if processes.map { |pr| pr.split("\s")[1].strip }.any? { |no| no == pid.to_s } | |
puts "shairport is already running. pid: #{pid}" | |
exit | |
else | |
puts "process not found pid: #{pid}" | |
puts "remove pid file, and restart shairport" | |
File.delete(pidfile) | |
shairport! | |
exit | |
end | |
else | |
puts "shairport is not running, start shairport..." | |
shairport! | |
exit | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment