Startup Script

You can add a startup script to install additional software in your environment, download content files, or anything else you'd like.

Startup scripts must complete in under 60 seconds and run from the /tmp directory. They're run as nt-user, but you have sudo access!

To add or modify your startup script, click the Settings icon in the left sidebar and locate the Startup Script section:

Startup Script setting

Each script is executed with Bash. Keep in mind that your script will run each time the content loads, which may slow down content loading times.

If you are trying to install software using the startup script and running into issues, just let us know! We may be able to add that software to the stack for you.

When a startup script is run, it will save three files to the starting directory (/home/nt-user/workspace by default):

  • .startup.stdout: The STDOUT from running the script (saved if there is any)

  • .startup.stderr: The STDERR from running the script (saved if there is any)

  • .startup.status: The status from running the script (saved if non-zero)

These files will be hidden from users by default because of the.at the beginning of the file name.

Your startup script will run after any course-wide startup script.

Examples

Startup scripts can be used for a number of reasons. Here are a few examples:

Pre-Installing a Package

To install a Pip package, you can do:

#!/bin/bash
sudo pip install python_speech_features

For example, if you want Python 3.6 to run when the user types python in the terminal, you can do:

sudo ln -sfn /usr/bin/python3.6 /usr/bin/python

Loading an Initial Database

In this example, the start-up script creates and populates a database by running the .setup.sql file below:

sudo systemctl restart mysql
sudo mysql < /root/sandbox/.setup.sql
.setup.sql
.setup.sql
--
-- Create Database: `employee`
--
DROP DATABASE IF EXISTS `employee`;
CREATE DATABASE `employee`;
USE `employee`;
DROP TABLE IF EXISTS employees;
CREATE TABLE employees
(
emp_no INT,
emp_name VARCHAR(50),
email VARCHAR(50),
depart_no INT,
comm INT,
salary INT
);
INSERT INTO employees
VALUES
(1234, "Amy", "amy@awesomenes.com", 1, 20, 30000),
(2345, "Bob", "bob@awesomenes.com", 3, 800, 50000),
(3456, "Charlie", "charlie@awesomenes.com", 1, 1500, 45000),
(4567, "Danielle", "danielle@awesomenes.com", 2, 200, 40000),
(5678, "Ethan", "ethan@awesomenes.com", 3, 0, 60000),
(6789, "Fred", "fred@awesomenes.com", 3, 500, 35000),
(1, "George", "lisa@awesomenes.com", 3, 600, 50000),
(2, "Henry", "henry@awesomenes.com", 2, 900, 63000),
(3, "Ava-May", "ava-may@awesomenes.com", 2, 1000, 50000),
(4, "Isabel", "isabel@awesomenes.com", 1, 20, 90000);