Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: built-in script runner #252

Merged
merged 4 commits into from
Aug 1, 2023
Merged

feat: built-in script runner #252

merged 4 commits into from
Aug 1, 2023

Conversation

de-sh
Copy link
Contributor

@de-sh de-sh commented Jun 28, 2023

Closes #

Changes

Script runner allows user to send custom scripts that are executed on the device with sh.

Why?

User needs to run a shell script quickly on the connected device.

Trials Performed

  1. Start uplink with appropriate config:
action_redirections = { "send_file" = "run_script" }
script_runner = [{ name = "run_script" }]

persistence_path = "/var/tmp/uplink"

[downloader]
actions = [{ name = "send_file" }]
path = "/var/tmp/uplink"
  1. Trigger send_file action with following script:
#!/bin/sh

echo 'This works'
  1. Observe the execution of script on device:
 2023-06-28T16:02:57.835734Z  INFO uplink::collector::downloader: Downloading from https://firmware.stage.bytebeam.io/api/v1/file/b307b17e-d0ec-4e7e-8e60-beb243b45e41/artifact into /var/tmp/uplink/send_file/save.sh

  2023-06-28T16:02:57.835865Z  INFO uplink::collector::downloader: Firmware downloaded successfully

  2023-06-28T16:02:57.835984Z  INFO uplink::base::bridge: Action response = ActionResponse { action_id: "893", device_id: None, sequence: 2, timestamp: 1687968177835, state: "Downloading", progress: 99, errors: [], done_response: None }

  2023-06-28T16:02:57.836041Z TRACE uplink::base::bridge::stream: Flushing stream name: action_status, topic: /tenants/demo/devices/1001/action/status

  2023-06-28T16:02:57.836078Z  INFO uplink::base::bridge: Action response = ActionResponse { action_id: "893", device_id: None, sequence: 3, timestamp: 1687968177835, state: "Downloaded", progress: 100, errors: [], done_response: Some(Action { device_id: None, action_id: "893", kind: "process", name: "send_file", payload: "{\"url\":\"https://firmware.stage.bytebeam.io/api/v1/file/b307b17e-d0ec-4e7e-8e60-beb243b45e41/artifact\",\"content_length\":29,\"file_name\":\"save.sh\",\"download_path\":\"/var/tmp/uplink/send_file/save.sh\"}" }) }

  2023-06-28T16:02:57.836121Z TRACE uplink::base::bridge::stream: Flushing stream name: action_status, topic: /tenants/demo/devices/1001/action/status

  2023-06-28T16:02:57.836127Z TRACE uplink::base::serializer: Data received on stream: action_status; message count = 1; batching latency = 0

  2023-06-28T16:02:57.836180Z DEBUG uplink::base::serializer: publishing on /tenants/demo/devices/1001/action/status with size = 108

  2023-06-28T16:02:57.836212Z TRACE uplink::base::serializer: Data received on stream: action_status; message count = 1; batching latency = 0

  2023-06-28T16:02:57.836223Z DEBUG uplink::base::serializer: publishing on /tenants/demo/devices/1001/action/status with size = 108

  2023-06-28T16:02:57.836434Z DEBUG uplink::base::mqtt: Outgoing = Publish(12)

  2023-06-28T16:02:57.836491Z DEBUG uplink::base::mqtt: Outgoing = Publish(13)

  2023-06-28T16:02:57.838979Z ERROR uplink::collector::script_runner: Failed to deserialize script output: "This works"; Error: expected value at line 1 column 1

  2023-06-28T16:02:57.839043Z  INFO uplink::collector::script_runner: Action done!! Status = Ok(ExitStatus(unix_wait_status(0)))

  2023-06-28T16:02:57.839126Z  INFO uplink::base::bridge: Action response = ActionResponse { action_id: "893", device_id: None, sequence: 0, timestamp: 1687968177839, state: "Completed", progress: 100, errors: [], done_response: None }
  1. Observe updates on platform:
    image

P.S: there needs to be a discussion about extracting action_status from stdout.
P.P.S: name user triggered action send_script and redirect it as run_script within the config as a best practice.

@de-sh de-sh requested a review from tekjar June 28, 2023 16:04
@de-sh de-sh marked this pull request as ready for review June 28, 2023 16:05
@de-sh de-sh requested a review from tekjar July 21, 2023 06:03
@de-sh de-sh changed the title feat: impelement script runner feat: built-in script runner Jul 26, 2023
@de-sh de-sh merged commit b7a9a56 into main Aug 1, 2023
2 checks passed
@de-sh de-sh deleted the script-runner branch August 1, 2023 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants