

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# キュー環境でパスを設定する
<a name="set-the-path"></a>

OpenJD 環境を使用して、 環境で新しいコマンドを提供します。まず、スクリプトファイルを含むディレクトリを作成し、そのディレクトリを`PATH`環境変数に追加します。これにより、スクリプト内の実行可能ファイルは、毎回ディレクトリパスを指定することなく実行できます。環境定義の変数のリストでは変数を変更できないため、代わりにスクリプトを実行して変更します。スクリプトがモノをセットアップして を変更すると`PATH`、 コマンド を使用して変数を OpenJD ランタイムにエクスポートします`echo "openjd_env: PATH=$PATH"`。

## 前提条件
<a name="set-prerequisites"></a>

 Deadline Cloud サンプル github リポジトリの[環境変数を使用してサンプルジョブバンドル](https://github.com/aws-deadline/deadline-cloud-samples/tree/mainline/job_bundles/job_env_vars/template.yaml)を実行するには、次の手順を実行します。

1.  キューと関連する Linux フリートを持つ Deadline Cloud ファームがない場合は、[Deadline Cloud コンソール](https://console.aws.amazon.com/deadlinecloud/home)のガイド付きオンボーディングエクスペリエンスに従って、デフォルト設定で作成します。

1.  ワークステーションに Deadline Cloud CLI と Deadline Cloud モニターがない場合は、ユーザーガイドの[「Deadline Cloud 送信者の設定](https://docs.aws.amazon.com/deadline-cloud/latest/userguide/submitter.html)」の手順に従ってください。

1.  `git` を使用して [Deadline Cloud サンプル GitHub リポジトリ](https://github.com/aws-deadline/deadline-cloud-samples)のクローンを作成します。

   ```
   git clone https://github.com/aws-deadline/deadline-cloud-samples.git
    Cloning into 'deadline-cloud-samples'...
    ...
   cd deadline-cloud-samples/job_bundles
   ```

## パスサンプルを実行する
<a name="path-run-sample"></a>

1.  Deadline Cloud CLI を使用して`job_env_with_new_command`サンプルを送信します。

   ```
    $ deadline bundle submit job_env_with_new_command
    Submitting to Queue: MySampleQueue
    ...
   ```

1.  Deadline Cloud モニターに新しいジョブが表示され、進行状況をモニタリングできます。キューに関連付けられたLinuxフリートがジョブのタスクを実行できるワーカーを持つと、ジョブは数秒で完了します。タスクを選択し、タスクパネルの右上メニューで**ログの表示**オプションを選択します。

    右側には、**Launch RandomSleepCommand と Task run の 2 **つのセッションアクションがあります。 ****ウィンドウの中央にあるログビューワーは、右側の選択したセッションアクションに対応します。

## セッションアクションとその定義を比較する
<a name="path-view-logs"></a>

このセクションでは、Deadline Cloud モニターを使用して、セッションアクションをジョブテンプレートで定義されている場所と比較します。これは前のセクションから続きます。

テキストエディタで [job\_env\_with\_new\_command/template.yaml](https://github.com/aws-deadline/deadline-cloud-samples/tree/mainline/job_bundles/job_env_with_new_command/template.yaml) ファイルを開きます。セッションアクションをジョブテンプレートで定義されている場所と比較します。

1.  Deadline Cloud モニターで **RandomSleepCommand **セッション起動アクションを選択します。ログ出力は次のように表示されます。

   ```
    2024/07/16 17:25:32-07:00
    2024/07/16 17:25:32-07:00 ==============================================
    2024/07/16 17:25:32-07:00 --------- Entering Environment: RandomSleepCommand
    2024/07/16 17:25:32-07:00 ==============================================
    2024/07/16 17:25:32-07:00 ----------------------------------------------
    2024/07/16 17:25:32-07:00 Phase: Setup
    2024/07/16 17:25:32-07:00 ----------------------------------------------
    2024/07/16 17:25:32-07:00 Writing embedded files for Environment to disk.
    2024/07/16 17:25:32-07:00 Mapping: Env.File.Enter -> /sessions/session-ab132a51b9b54d5da22cbe839dd946baaw1c8hk5/embedded_filesf3tq_1os/tmpbt8j_c3f
    2024/07/16 17:25:32-07:00 Mapping: Env.File.SleepScript -> /sessions/session-ab132a51b9b54d5da22cbe839dd946baaw1c8hk5/embedded_filesf3tq_1os/tmperastlp4
    2024/07/16 17:25:32-07:00 Wrote: Enter -> /sessions/session-ab132a51b9b54d5da22cbe839dd946baaw1c8hk5/embedded_filesf3tq_1os/tmpbt8j_c3f
    2024/07/16 17:25:32-07:00 Wrote: SleepScript -> /sessions/session-ab132a51b9b54d5da22cbe839dd946baaw1c8hk5/embedded_filesf3tq_1os/tmperastlp4
    2024/07/16 17:25:32-07:00 ----------------------------------------------
    2024/07/16 17:25:32-07:00 Phase: Running action
    2024/07/16 17:25:32-07:00 ----------------------------------------------
    2024/07/16 17:25:32-07:00 Running command sudo -u job-user -i setsid -w /sessions/session-ab132a51b9b54d5da22cbe839dd946baaw1c8hk5/tmpbwrquq5u.sh
    2024/07/16 17:25:32-07:00 Command started as pid: 2205
    2024/07/16 17:25:32-07:00 Output:
    2024/07/16 17:25:33-07:00 openjd_env: PATH=/sessions/session-ab132a51b9b54d5da22cbe839dd946baaw1c8hk5/bin:/opt/conda/condabin:/home/job-user/.local/bin:/home/job-user/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/var/lib/snapd/snap/bin
    No newer logs at this moment.
   ```

    ジョブテンプレートの次の行で、このアクションが指定されました。

   ```
    jobEnvironments:
    - name: RandomSleepCommand
      description: Adds a command 'random-sleep' to the environment.
      script:
        actions:
          onEnter:
            command: bash
            args:
            - "{{Env.File.Enter}}"
        embeddedFiles:
        - name: Enter
          type: TEXT
          data: |
            #!/bin/env bash
            set -euo pipefail
   
            # Make a bin directory inside the session's working directory for providing new commands
            mkdir -p '{{Session.WorkingDirectory}}/bin'
   
            # If this bin directory is not already in the PATH, then add it
            if ! [[ ":$PATH:" == *':{{Session.WorkingDirectory}}/bin:'* ]]; then
              export "PATH={{Session.WorkingDirectory}}/bin:$PATH"
   
              # This message to Open Job Description exports the new PATH value to the environment
              echo "openjd_env: PATH=$PATH"
            fi
   
            # Copy the SleepScript embedded file into the bin directory
            cp '{{Env.File.SleepScript}}' '{{Session.WorkingDirectory}}/bin/random-sleep'
            chmod u+x '{{Session.WorkingDirectory}}/bin/random-sleep'
        - name: SleepScript
          type: TEXT
          runnable: true
          data: |
            ...
   ```

1.  Deadline Cloud モニターで ** StepEnv **セッション起動アクションを選択します。ログ出力は次のように表示されます。

   ```
    2024/07/16 17:25:33-07:00
    2024/07/16 17:25:33-07:00 ==============================================
    2024/07/16 17:25:33-07:00 --------- Running Task
    2024/07/16 17:25:33-07:00 ==============================================
    2024/07/16 17:25:33-07:00 ----------------------------------------------
    2024/07/16 17:25:33-07:00 Phase: Setup
    2024/07/16 17:25:33-07:00 ----------------------------------------------
    2024/07/16 17:25:33-07:00 Writing embedded files for Task to disk.
    2024/07/16 17:25:33-07:00 Mapping: Task.File.Run -> /sessions/session-ab132a51b9b54d5da22cbe839dd946baaw1c8hk5/embedded_filesf3tq_1os/tmpdrwuehjf
    2024/07/16 17:25:33-07:00 Wrote: Run -> /sessions/session-ab132a51b9b54d5da22cbe839dd946baaw1c8hk5/embedded_filesf3tq_1os/tmpdrwuehjf
    2024/07/16 17:25:33-07:00 ----------------------------------------------
    2024/07/16 17:25:33-07:00 Phase: Running action
    2024/07/16 17:25:33-07:00 ----------------------------------------------
    2024/07/16 17:25:33-07:00 Running command sudo -u job-user -i setsid -w /sessions/session-ab132a51b9b54d5da22cbe839dd946baaw1c8hk5/tmpz81iaqfw.sh
    2024/07/16 17:25:33-07:00 Command started as pid: 2256
    2024/07/16 17:25:33-07:00 Output:
    2024/07/16 17:25:34-07:00 + random-sleep 12.5 27.5
    2024/07/16 17:26:00-07:00 Sleeping for duration 26.90
    2024/07/16 17:26:00-07:00 ----------------------------------------------
    2024/07/16 17:26:00-07:00 Uploading output files to Job Attachments
    2024/07/16 17:26:00-07:00 ----------------------------------------------
   ```

1.  ジョブテンプレートの次の行で、このアクションが指定されました。

   ```
    steps:
    - name: EnvWithCommand
      script:
        actions:
          onRun:
            command: bash
            args:
            - '{{Task.File.Run}}'
        embeddedFiles:
        - name: Run
          type: TEXT
          data: |
            set -xeuo pipefail
   
            # Run the script installed into PATH by the job environment
            random-sleep 12.5 27.5
      hostRequirements:
        attributes:
        - name: attr.worker.os.family
          anyOf:
          - linux
   ```