add synapsectl command for deploying to device, and associated build / package / deploy scripts#106
add synapsectl command for deploying to device, and associated build / package / deploy scripts#106
Conversation
| ''' | ||
|
|
||
| cmd = [ | ||
| "docker", |
There was a problem hiding this comment.
Do we detect whether docker is installed upfront and not let them get this far if docker won't be found or isn't running?
maxhodak
left a comment
There was a problem hiding this comment.
this is unreviewable, way way too long
| # Send the command to start the application | ||
| shell.send(f"sudo systemctl start {app_name}.service\n") | ||
| time.sleep(2) # Wait for the command to execute | ||
|
|
||
| # Collect output to check for errors | ||
| output = "" | ||
| while shell.recv_ready(): | ||
| chunk = shell.recv(4096).decode("utf-8") | ||
| output += chunk | ||
|
|
||
| # If there's an error, we'll usually see it in the output | ||
| if "error" in output.lower() or "failed" in output.lower(): | ||
| progress.update(task, visible=False) | ||
| console.print( | ||
| f"[bold red]Error:[/bold red] Failed to start application:\n{output}" | ||
| ) | ||
| return False |
There was a problem hiding this comment.
Scifi will be responsible for managing start/stop of the server. This can be replaced with configuring the device and then starting
|
|
||
| # Send su command | ||
| shell.send("su -\n") | ||
| time.sleep(1) # Wait for password prompt |
There was a problem hiding this comment.
is there no way to ensure the command has been executed beyond sleeping? This seems both slow and unreliable
There was a problem hiding this comment.
Actually, this should all be handled on the scifi side, both for reliability and to keep SSH restricted.
| # Deploy directly using paramiko | ||
| client = None | ||
| sftp = None | ||
| shell = None | ||
|
|
||
| # Create SSH client | ||
| import paramiko | ||
|
|
||
| client = paramiko.SSHClient() | ||
| client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) |
There was a problem hiding this comment.
there are sftp utility functions in synapse/client/sftp.py that could probably wrap a lot of this
| -DVCPKG_INSTALLED_DIR=${VCPKG_ROOT}/vcpkg_installed \ | ||
| -DBUILD_SHARED_LIBS=ON \ | ||
| -DCMAKE_BUILD_TYPE=Release \ | ||
| -DBUILD_FOR_ARM64=ON && |
There was a problem hiding this comment.
nit: this is scifi-server specific and can probably be removed
| set -e | ||
| APP_NAME="{app_name}" | ||
|
|
||
| # Copy the template ops directory to a temporary working area inside the container | ||
| TEMPLATE_DIR="/synapse_ops" | ||
| TEMP_DIR="/tmp/synapse_package_ops" | ||
| rm -rf "$TEMP_DIR" | ||
| cp -r "$TEMPLATE_DIR" "$TEMP_DIR" | ||
|
|
||
| # Replace placeholders in every file | ||
| find "$TEMP_DIR" -type f -exec sed -i 's/{{{{APP_NAME}}}}/'"$APP_NAME"'/g' {{}} + | ||
|
|
||
| # Rename the systemd service template to the correct name | ||
| # The template file is literally called "{{APP_NAME}}.service" (double braces). | ||
| if [ -f "$TEMP_DIR/package/systemd/{{{{APP_NAME}}}}.service" ]; then | ||
| mv "$TEMP_DIR/package/systemd/{{{{APP_NAME}}}}.service" "$TEMP_DIR/package/systemd/$APP_NAME.service" | ||
| fi | ||
|
|
||
| # Ensure the packaging script is executable and points to the correct source dir | ||
| chmod +x "$TEMP_DIR/package/package.sh" | ||
| sed -i 's|SOURCE_DIR=.*|SOURCE_DIR="/home/workspace"|' "$TEMP_DIR/package/package.sh" | ||
|
|
||
| # Finally, run the packaging script from the workspace root so that the .deb lands | ||
| # in the application directory that is mounted from the host. | ||
| cd /home/workspace | ||
| bash "$TEMP_DIR/package/package.sh" | ||
| ''' |
There was a problem hiding this comment.
can this all be a part of package.sh? Then we wouldnt have inline bash scripts in python.
|
|
||
| # Reload and start the service | ||
| systemctl daemon-reload | ||
| systemctl enable "${SYNAPSE_APP_EXE}" No newline at end of file |
There was a problem hiding this comment.
This needs to be removed so the app doesnt automatically start
| if ! renice -n -10 $$ > /dev/null 2>&1; then | ||
| echo "Failed to set process priority" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Set CPU scheduler to FIFO | ||
| # Might drop this down if the system is unstable | ||
| if ! chrt -f -p 50 $$ > /dev/null 2>&1; then | ||
| echo "Failed to set CPU scheduler to FIFO" | ||
| exit 1 | ||
| fi |
There was a problem hiding this comment.
these should all be removed
…ython into emma-deploy
gilbert-sci
left a comment
There was a problem hiding this comment.
we will break this out but this is a good start.

No description provided.