Skip to content

Add direct server management via command line #2834

Closed
@m-roberts

Description

@m-roberts

It would be great if Sonic Pi came with the ability to easily start/stop the server (e.g. a simplesonic-pi-server CLI)

(Note: this PR refers specifically to Raspberry Pi, but I see no reason this wouldn't be useful for other platforms)

Currently on pi-topOS, we are using this script in /usr/bin/sonic-pi-server:

#!/bin/bash

logFile="/tmp/sonic-pi-server-log.txt"

try_start_server() {
	local sonicPiServerPath="${1}"

	if [[ -f "${sonicPiServerPath}" ]]; then
		echo "Sonic Pi server found: ${sonicPiServerPath}"
		echo "Log file: ${logFile}"

		cmd="/usr/bin/ruby -E utf-8 ${sonicPiServerPath}"
		echo
		echo "Running Sonic Pi server in the background..."
		echo -e "\t${cmd}"
		echo
		echo
		echo "Press Ctrl+C at any time to stop."
		echo
		echo "Please wait for Sonic Pi Server to start..."
		echo
		/usr/bin/ruby -E utf-8 "${sonicPiServerPath}" 2>&1 | tee "${logFile}" | ag "Sonic Pi Server successfully booted."
		return 0
	else
		echo "Sonic Pi server not found at path: ${sonicPiServerPath}"
		return 1
	fi
}

# Try /opt first (Sonic Pi's "sonic-pi" package preferred to RPi's "sonic-pi-server" package)
if ! try_start_server "/opt/sonic-pi/app/server/ruby/bin/sonic-pi-server.rb" &&
	! try_start_server "/usr/lib/sonic-pi/server/bin/sonic-pi-server.rb"; then
	echo "The Sonic Pi server application could not be found. You may need to check for updates or re-install Sonic Pi"
fi

This handles a couple of things:

  • file path of the server works for both RPi-packaged and community packaged
    • This wouldn't be necessary if this were available out-of-the-box in the package - file path would simply be patched as part of the Debian packaging, as it does already
  • Adds some sort of text print-out to wait for server to come up, and only prints out the line that shows that it's live
    • This was just a workaround so that the user could know when it's up and running - I am sure that a more native solution would be more appropriate
  • Stores the rest of the output in a log file
    • Again, this is really only because the rest of the output isn't being printed

This script won't be going anywhere any time soon (Sonic Pi updates take a while to make it to Raspberry Pi OS...!), but it would be great if in future handling the server via a convenient entrypoint script was easier!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions