Skip to content

Instantly share code, notes, and snippets.

@ykpythemind
Last active January 19, 2020 16:10
Show Gist options
  • Save ykpythemind/b1b1ae2796acb6df160ec745b7ad2d21 to your computer and use it in GitHub Desktop.
Save ykpythemind/b1b1ae2796acb6df160ec745b7ad2d21 to your computer and use it in GitHub Desktop.
shairport sync up
#!/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