Open hamishlow opened 2 months ago
Hi,
Thanks for the kind words.
I have not tested the headless setup of the PI in my env. I'll look into it. In the mean time can you post the output of the command serve -s build
while in headless mode.
I am assuming that you tried launching it while connected in SSH right, or you have a script that automate the launch in the background?
As for the integration with the other repo, it would actually be a good idea for those interested. This is more an enhancement on the other repo pianoteq-pi. But I wouldn't mind helping in some way. I'll look at that repo and see if I can post a pull request to have it include this project as well.
Thx
Robert
Yes, pianoteq-pi gave me a script to launch Pianoteq on a headless startup, I then followed your instructions for Option 2 and added info to the startup script to launch the ptq-webapp:
As I mentioned, I can run the script and it launches the webapp on port 3000 from VNC - which means I can use the webapp from my phone, but on headless startup I get the following error message log, pianoteq runs but the webapp goes to port 42253:
HTTP 02/09/2024 22:44:14 IP ADDRESS GET / HTTP 02/09/2024 22:44:14 IP ADDRESS Returned 200 in 229 ms HTTP 02/09/2024 22:44:14 IP ADDRESS GET /static/css/main.5ecd60fb.chunk.css HTTP 02/09/2024 22:44:14 IP ADDRESS GET /static/js/2.81c38672.chunk.js HTTP 02/09/2024 22:44:14 IP ADDRESS GET /static/js/main.0c2630ce.chunk.js HTTP 02/09/2024 22:44:14 IP ADDRESS Returned 200 in 28 ms HTTP 02/09/2024 22:44:14 IP ADDRESS Returned 304 in 30 ms HTTP 02/09/2024 22:44:14 IP ADDRESS Returned 304 in 27 ms HTTP 02/09/2024 22:44:14 IP ADDRESS GET /assets/midi.png HTTP 02/09/2024 22:44:14 IP ADDRESS GET /assets/metronome-tick.png HTTP 02/09/2024 22:44:14 IP ADDRESS Returned 200 in 14 ms HTTP 02/09/2024 22:44:14 IP ADDRESS Returned 200 in 11 ms HTTP 02/09/2024 22:44:14 IP ADDRESS GET /manifest.json HTTP 02/09/2024 22:44:14 IP ADDRESS Returned 304 in 8 ms 2024-09-02 22:44:26 - Attempting to launch ptq webapp 2024-09-02 22:44:26 - Successfully changed to ptq-client-webapp directory INFO Accepting connections at http://localhost:42253
Here's the adapted start.sh script that runs on headless startup...
#!/usr/bin/env bash
set -e # Exit immediately if a command exits with a non-zero status.
exec_path="/home/pianoteq/Pianoteq 8 STAGE/arm-64bit/Pianoteq 8 STAGE"
base_args="--serve 0.0.0.0:8081 --multicore max --midimapping"
base_cmd=("${exec_path}" ${base_args})
sudo cpufreq-set -r -g performance || echo "Failed to set CPU frequency to performance mode"
if [ "$#" -eq 0 ] ; then
# open directly
sudo systemctl stop pianoteq || echo "Failed to stop pianoteq service"
"${base_cmd[@]}"
sudo systemctl start pianoteq || echo "Failed to start pianoteq service"
else
# run from systemctl
"${base_cmd[@]}" "$@"
fi
# Set up logging
LOG_FILE="/home/pianoteq/ptq_webapp_startup.log"
log_message() {
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >> "$LOG_FILE"
}
# Source user profile to ensure environment is set correctly
source /home/pianoteq/.bash_profile
source /home/pianoteq/.bashrc
# Launch ptq webapp
log_message "Attempting to launch ptq webapp"
# Change to parent directory
if ! cd ..; then
log_message "Error: Failed to change to parent directory"
exit 1
fi
# Change to ptq-client-webapp directory
if ! cd ptq-client-webapp; then
log_message "Error: Failed to change to /home/pianoteq/ptq-client-webapp directory"
exit 1
fi
log_message "Successfully changed to ptq-client-webapp directory"
# Check if the port is already in use before starting the server
if sudo lsof -Pi :3000 -sTCP:LISTEN -t >/dev/null ; then
log_message "Error: Port 3000 is already in use"
exit 1
fi
sleep 8
# Run npx serve
if ! sudo -u pianoteq npx serve -s build -l > >(tee -a "$LOG_FILE") 2> >(tee -a "$LOG_FILE" >&2); then
log_message "Error: Failed to run 'sudo npx serve -s build'"
exit 1
fi
log_message "ptq webapp launched successfully"
Actually I think I messed this up somehow and can't replicate... pianoteq launches with this, but in trying to get it to launch ptq-webapp on startup it no longer launches from the VNC either at present.. obviously I don´t really know what I am doing... I'll wait for wiser minds (yours) to find a solution.... much appreciated!
OK,
An easy test would be to set the port yourself instead of using the default one by npx serve
. So instead of the above command pls change it to the following:
sudo -u pianoteq npx serve -s build -l -p 8080 > >(tee -a "$LOG_FILE") 2> >(tee -a "$LOG_FILE" >&2)
Change the port number to what ever is available on a headless setup. Then access the website using the port number you used in the command above.
Let me know how it went.
Robert
Hi Robert,
The script now works on a headless Pi setup after having run the build command... here's the script. It launches Pianoteq 8 on startup and the webapp on port 3000 - so I can now use your webapp from my phone. Thanks so much!
`#!/usr/bin/env bash
LOG_FILE="/home/$USERNAME/ptq_webapp_startup.log"
log_message() { echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >> "$LOG_FILE" }
log_message "Script started with PID: $$"
trap 'kill $(jobs -p)' EXIT
log_message "Sourcing user profiles" source /home/$USERNAME/.bash_profile source /home/$USERNAME/.bashrc
log_message "Setting up Pianoteq" exec_path="/home/$USERNAME/Pianoteq 8 STAGE/arm-64bit/Pianoteq 8 STAGE" base_args="--serve 0.0.0.0:8081 --multicore max --midimapping"
base_cmd=("${exec_path}" ${base_args})
log_message "Attempting to set CPU frequency" if ! sudo cpufreq-set -r -g performance; then log_message "Failed to set CPU frequency to performance mode" else log_message "CPU frequency set to performance mode" fi
log_message "Checking script arguments" if [ "$#" -eq 0 ] ; then log_message "No arguments provided, opening directly" if ! sudo systemctl stop pianoteq; then log_message "Failed to stop pianoteq service" else log_message "Pianoteq service stopped" fi log_message "Launching Pianoteq" "${base_cmd[@]}" & log_message "Pianoteq launched in background" if ! sudo systemctl start pianoteq; then log_message "Failed to start pianoteq service" else log_message "Pianoteq service started" fi else log_message "Arguments provided, running from systemctl" "${base_cmd[@]}" "$@" & log_message "Pianoteq launched in background with arguments" fi
sleep 5
log_message "Attempting to launch ptq webapp"
log_message "Changing to ptq-client-webapp directory" if ! cd /home/$USERNAME/ptq-client-webapp; then log_message "Error: Failed to change to /home/$USERNAME/ptq-client-webapp directory" exit 1 fi
log_message "Successfully changed to ptq-client-webapp directory"
log_message "Checking if port 3000 is in use" if sudo lsof -Pi :3000 -sTCP:LISTEN -t >/dev/null ; then log_message "Error: Port 3000 is already in use" exit 1 fi
log_message "Running npx serve" if ! sudo -u $USERNAME npx serve -s build -p 3000 &>> "$LOG_FILE"; then log_message "Error: Failed to run 'sudo -u $USERNAME npx serve -s build -p 3000'" exit 1 fi
log_message "ptq webapp launched successfully" `
I also changed the permissions on the script to make it executable..
Something else that would improve the webapp would be the ability to run the reset command, (the command Alt+P from the GUI)... as sometimes it freezes, and it doesn't seem possible to be able to reset from the webapp at present...
Hi,
Glad to see that you were successful. OK, I'll add that feature in the list of todos.
Thx
Hi @hamishlow ,
Would you mind pointing to the documentation that mention the "Alt-P" command. I cannot seem to find it on the Mozart's website.
Thx
Hi Robert, Here's a little screenshot of the Pianoteq GUI with the note on hover over the reset button. When I'm running Pianoteq on the Pi headless (on a Raspberry Pi 4B, sometimes it is running stably for a long time, sometimes it crashes. At present the only options I have are to restart, or to enter via VNC open the GUI and press that button. Thanks so much for your work on this!
Thanks so much Robert for this great script, on a local install on a headless setup on a raspberry pi it works perfectly, however only when I launch the script from a VNC environment.
I am having difficulty though getting it the script to run from startup on a headless boot.
I got Pianoteq 8 working on a raspberry pi 4B with the help of pianoteq-pi. Your script is the perfect complement, as while pianoteq-pi got pianoteq working, I could not change settings on pianoteq without going in through a VNC to open the gui and change instrument.
Your script works perfectly if launched from a VNC environment (with the webapp to port 3000 as intended) however on a headless boot the webapp ports to something completely different and I can't figure out why it won't port to 3000.
This is more of a feature request than an issue, and beyond my limited abilities. It would be amazing if pianoteq-pi and ptq-client-webapp worked together perfectly!
I've also posted this suggestion/feature request on https://github.com/youfou/pianoteq-pi/issues/9
Thanks for your consideration!