0

Signal Machine

by
Published Oct 17, 2025

Send a signal to a specific Machine within an app using the details provided in the request body.

Script fly Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Fly = {
3
  token: string;
4
};
5
/**
6
 * Signal Machine
7
 * Send a signal to a specific Machine within an app using the details provided in the request body.
8

9
 */
10
export async function main(
11
  auth: Fly,
12
  app_name: string,
13
  machine_id: string,
14
  body: {
15
    signal?:
16
      | "SIGABRT"
17
      | "SIGALRM"
18
      | "SIGFPE"
19
      | "SIGHUP"
20
      | "SIGILL"
21
      | "SIGINT"
22
      | "SIGKILL"
23
      | "SIGPIPE"
24
      | "SIGQUIT"
25
      | "SIGSEGV"
26
      | "SIGTERM"
27
      | "SIGTRAP"
28
      | "SIGUSR1";
29
  },
30
) {
31
  const url = new URL(
32
    `https://api.machines.dev/v1/apps/${app_name}/machines/${machine_id}/signal`,
33
  );
34

35
  const response = await fetch(url, {
36
    method: "POST",
37
    headers: {
38
      "Content-Type": "application/json",
39
      Authorization: "Bearer " + auth.token,
40
    },
41
    body: JSON.stringify(body),
42
  });
43
  if (!response.ok) {
44
    const text = await response.text();
45
    throw new Error(`${response.status} ${text}`);
46
  }
47
  return await response.text();
48
}
49