tencent cloud

Tencent Cloud TI Platform

Related Agreement
プライバシーポリシー
データ処理とセキュリティ契約
ドキュメントTencent Cloud TI Platform

Using Lifecycle Scripts

フォーカスモード
フォントサイズ
最終更新日: 2025-05-09 15:35:27

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:
#!/bin/bash
sudo -u tione -i <<'EOF'

# This will affect only the Jupyter kernel called "conda_python3".
source /opt/conda/bin/activate python3

# Replace fire with the name of the package you want to install.
pip install fire
# You can also perform "conda install" here as well.

source /opt/conda/bin/deactivate

EOF
For example, to install Python Fire in all kernels, you can write the script as follows:
#!/bin/bash
sudo -u tione -i <<'EOF'

# Note that "base" is special environment name, include it there as well.

for env in base /opt/conda/envs/*; do
source /opt/conda/bin/activate $(basename "$env")

# Installing packages in the Jupyter system environment can affect stability of your tione
# Notebook Instance. You can remove this check if you'd like to install Jupyter extensions, etc.
if [ $env = 'JupyterSystemEnv' ]; then
continue
fi

# Replace myPackage with the name of the package you want to install.
pip install fire
# You can also perform "conda install" here as well.

source /opt/conda/bin/deactivate
done

EOF


ヘルプとサポート

この記事はお役に立ちましたか?

フィードバック