Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add direct server management via command line #3157

m-roberts started this conversation in Feature/Improvement Ideas
Discussion options

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!

You must be logged in to vote

Replies: 2 comments 1 reply

Comment options

Hi there,

I've made recent architectural moves to make this easier in the future. If you look at the dev branch you'll find a new Ruby script called daemon.rb which is both in charge of spawning all the required process for the Server to operate correctly and also for ensuring that they are all correctly terminated when they are no longer needed. I'll likely be adding more high-level script support in the future after the dust has settled a little.

https://github.com/sonic-pi-net/sonic-pi/blob/dev/app/server/ruby/bin/daemon.rb

You must be logged in to vote
0 replies
Comment options

Hey @m-roberts,

now v4 of Sonic Pi is out, did you get chance to check out the new process booting infrastructure? Does it serve your purposes as is, or does it still need some modification?

I'm assuming we still need to consider some sort of basic CLI around daemon.rb. However, I don't fully understand your use case. Are you using Sonic Pi without the built-in GUI and using your own?

You must be logged in to vote
1 reply
Comment options

Hi Sam - I think this can be distilled down to: "providing an easy way to start Sonic Pi in a headless environment, and know when the server is started".

In my opinion, this is best provided by a separate entrypoint command (sonic-pi-server) that gives control of the terminal to the user when the server has started. This would allow people to run scripts like this:

#!/bin/bash
sonic-pi-server --daemon # Disconnect from process when the server is working
exit_code=$?
if [[ ${exit_code} -ne 0 ]]; then
 echo "Sonic Pi server failed to start - check the logs"
 exit 1
fi
/path/to/my_code_that_talks_to_sonic_pi_daemon.ext # or other frontend

If this can be achieved in another way, that would be fine too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Converted from issue

This discussion was converted from issue #2834 on July 21, 2022 09:15.

AltStyle によって変換されたページ (->オリジナル) /