Lifecycle Script Configuration Rules
The lifecycle configuration provides shell scripts that run when a user creates or starts a dev machine instance, enabling users to install custom dependencies and personalize the dev machine environment.
The lifecycle configuration follows the following rules:
Creation script: A script that runs after it is created for the first time when you launch a dev machine instance. The script runs only once.
Startup script: A script that runs on every boot of a dev machine instance, including when it is created for the first time.
After Base64 encoding, each script cannot exceed 16,384 characters.
Each script will run as a root user.
The $PATH environment variable for each script is /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin.
Each script runs for a maximum of 5 minutes. A dev machine will fail to start when the time limit is exceeded. It should be avoided to install large dependencies in scripts. You can view the reason for failure on the details page, for example, "startup script timeout."
If an error occurs in scripts, a dev machine will also fail to start. You can view the reason for failure on the details page.
If scripts are copied from the editor to the TI-ONE webpage, ensure that the editor you used to edit the scripts uses the Unix-style orchestration.
Lifecycle Script Best Practices
The following shows a practical case of using the lifecycle configuration:
A lifecycle script runs with root account permissions, and a dev machine process runs as a TI-ONE user. To switch users, you can run sudo -u tione in the script to switch to the TI-ONE user.
The dev machine uses Conda to manage multiple kernels. You can activate conda env to install dependencies for different kernels.
For example, to install Python Fire in the kernel of conda_python3, you can write the startup script as follows:
sudo -u tione -i <<'EOF'
source /opt/conda/bin/activate python3
pip install fire
source /opt/conda/bin/deactivate
EOF
For example, to install Python Fire in all kernels, you can write the script as follows:
sudo -u tione -i <<'EOF'
for env in base /opt/conda/envs/*; do
source /opt/conda/bin/activate $(basename "$env")
if [ $env = 'JupyterSystemEnv' ]; then
continue
fi
pip install fire
source /opt/conda/bin/deactivate
done
EOF