CosmicAC Logo

Run a startup script in a GPU Container Job

Add commands that run as root each time a GPU Container Job starts.

Run commands each time a GPU Container Job starts. For example, you can install packages or start a service. To do this, add the commands to the job's startup script, /etc/cosmicac/startup-script.sh. CosmicAC runs the script as root.

Prerequisites

Before you start, make sure that you have the following.

  • The CosmicAC CLI installed and configured. See Install the CLI.
  • A GPU Container Job with the status Active.

Steps

Open a shell in the job

Run the following command. Replace <jobId> with the job ID and <containerId> with the container index.

cosmicac jobs shell <jobId> <containerId>

For information about how to find both values, see Connect to a GPU Container Job.

Edit the startup script

Open the script with sudo, because root owns the file.

sudo nano /etc/cosmicac/startup-script.sh

Add your commands, one per line. To save the file and exit, press Ctrl+O, press Enter, and then press Ctrl+X.

Restart the job

Run the following command. Replace <jobId> with the job ID.

cosmicac jobs restart <jobId>

The restart keeps your script, because it keeps the job's root disk. The script runs when the job starts again and on every later start.

Check that the script ran

Wait until the job is Active again. Then search the job's application logs for the result of the script.

cosmicac jobs logs <jobId> --search "startup-script finished"

The output shows a startup-script finished line with the exit code of the script. An exit code of 0 means that the script succeeded.

To see the output of the script, run cosmicac jobs logs <jobId>.

Help and troubleshooting

The script doesn't run

CosmicAC skips an empty script. Check that the file contains your commands.

sudo cat /etc/cosmicac/startup-script.sh
The exit code isn't 0

A command in the script failed. The output of the script is in the job's application logs, and in /var/log/cosmicac/startup-script.log in the container. Fix the command, and then restart the job.

Next steps

On this page