Under the hood, CoCalc provides you with a very flexible and versatile Linux environment. Due to the upgrade to Kubernetes, our (unofficial) support for using crontab files for periodic tasks was removed. Instead, there is a new and more flexible mechanism to use regular Bash, Python, or SageMath files to accomplish even more.
When a CoCalc project starts up, an instance of Supervisor is started and responsible for running:
- an instance of “local hub”. It is used for managing the project, communication with the outside world, monitoring, etc.
- sshd: the endpoint for remote SSH access
- initialization file: it sit inside your project and is only started if it exists.
It is located in your home directory and named
project_init.sh. As the name suggests, it is run via the Bash interpreter.
Initialization file management
Supervisor is configured to run this initialization file like background processes.
This means it checks the exit value of the process and restarts it if this code is not
Therefore, a script that runs without an error is not restarted.
On the other hand, if the process is terminated, interrupted or crashes – therefore the exit code is e.g.
1 – the process is restarted.
This adds some robustness to long running background jobs.
Example 1: record start time
A very simple example is to record the project’s start time.
Go to your home directory and create a file
project_init.sh with that content:
This is a very simple bash script, which pipes the output of the
date command into the file
In order to see its effect, the file needs to be saved and the project restarted. Give it a few seconds to come back online and run the script. After that (maybe click the refresh button in the file listing) you should see this file and its content might look like:
Other languages besides Bash?
You can run any language via bash’s
will run a Python 3 initialization file named