Skip to content

Instantly share code, notes, and snippets.

@samwan
Created June 1, 2018 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save samwan/fb98c9d3d05cc638079bc50b826fa7f1 to your computer and use it in GitHub Desktop.
Save samwan/fb98c9d3d05cc638079bc50b826fa7f1 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Adapting this auto-shutdown tutorial to work with Gradient Notebooks, which don't provide ssh access: https://paperspace.zendesk.com/hc/en-us/articles/115002807447"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [107 kB]\n",
"Ign:2 http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64 InRelease\n",
"Get:3 http://security.ubuntu.com/ubuntu xenial-security/universe Sources [81.2 kB]\n",
"Get:4 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [637 kB]\n",
"Get:5 http://security.ubuntu.com/ubuntu xenial-security/restricted amd64 Packages [12.7 kB]\n",
"Get:6 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 Packages [445 kB]\n",
"Get:7 http://archive.ubuntu.com/ubuntu xenial InRelease [247 kB] \n",
"Ign:8 http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64 InRelease\n",
"Get:9 http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64 Release [564 B]\n",
"Get:10 http://security.ubuntu.com/ubuntu xenial-security/multiverse amd64 Packages [3743 B]\n",
"Get:11 http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64 Release [564 B]\n",
"Get:12 http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64 Release.gpg [801 B]\n",
"Get:13 http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64 Release.gpg [801 B]\n",
"Get:14 http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64 Packages [113 kB]\n",
"Get:15 http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1604/x86_64 Packages [23.4 kB]\n",
"Get:16 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]\n",
"Get:17 http://archive.ubuntu.com/ubuntu xenial-backports InRelease [107 kB]\n",
"Get:18 http://archive.ubuntu.com/ubuntu xenial/universe Sources [9802 kB]\n",
"Get:19 http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages [1558 kB]\n",
"Get:20 http://archive.ubuntu.com/ubuntu xenial/restricted amd64 Packages [14.1 kB]\n",
"Get:21 http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages [9827 kB]\n",
"Get:22 http://archive.ubuntu.com/ubuntu xenial/multiverse amd64 Packages [176 kB]\n",
"Get:23 http://archive.ubuntu.com/ubuntu xenial-updates/universe Sources [256 kB]\n",
"Get:24 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [1012 kB]\n",
"Get:25 http://archive.ubuntu.com/ubuntu xenial-updates/restricted amd64 Packages [13.1 kB]\n",
"Get:26 http://archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [814 kB]\n",
"Get:27 http://archive.ubuntu.com/ubuntu xenial-updates/multiverse amd64 Packages [18.8 kB]\n",
"Get:28 http://archive.ubuntu.com/ubuntu xenial-backports/main amd64 Packages [5157 B]\n",
"Get:29 http://archive.ubuntu.com/ubuntu xenial-backports/universe amd64 Packages [8068 B]\n",
"Fetched 25.4 MB in 2s (8874 kB/s) \n",
"Reading package lists... Done\n",
"Reading package lists... Done\n",
"Building dependency tree \n",
"Reading state information... Done\n",
"The following additional packages will be installed:\n",
" libxss1\n",
"The following NEW packages will be installed:\n",
" libxss1 xprintidle\n",
"0 upgraded, 2 newly installed, 0 to remove and 85 not upgraded.\n",
"Need to get 15.0 kB of archives.\n",
"After this operation, 86.0 kB of additional disk space will be used.\n",
"Get:1 http://archive.ubuntu.com/ubuntu xenial/main amd64 libxss1 amd64 1:1.2.2-1 [8582 B]\n",
"Get:2 http://archive.ubuntu.com/ubuntu xenial/universe amd64 xprintidle amd64 0.2-10 [6466 B]\n",
"Fetched 15.0 kB in 0s (67.7 kB/s) \n",
"debconf: delaying package configuration, since apt-utils is not installed\n",
"Selecting previously unselected package libxss1:amd64.\n",
"(Reading database ... 19837 files and directories currently installed.)\n",
"Preparing to unpack .../libxss1_1%3a1.2.2-1_amd64.deb ...\n",
"Unpacking libxss1:amd64 (1:1.2.2-1) ...\n",
"Selecting previously unselected package xprintidle.\n",
"Preparing to unpack .../xprintidle_0.2-10_amd64.deb ...\n",
"Unpacking xprintidle (0.2-10) ...\n",
"Setting up libxss1:amd64 (1:1.2.2-1) ...\n",
"Setting up xprintidle (0.2-10) ...\n",
"Processing triggers for libc-bin (2.23-0ubuntu9) ...\n"
]
}
],
"source": [
"# Update apt-get and install xprintidle. \n",
"# Pass \"-y\" argument to say Yes at the prompts, otherwise notebook will freeze.\n",
"!apt-get -y update\n",
"!apt-get -y install xprintidle"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" % Total % Received % Xferd Average Speed Time Time Time Current\n",
" Dload Upload Total Spent Left Speed\n",
"100 807 100 807 0 0 4664 0 --:--:-- --:--:-- --:--:-- 4691\n",
"usr/local/bin/idle_shutdown.sh\n",
"etc/default/idle_shutdown\n",
"etc/init/idle_shutdown.conf\n"
]
}
],
"source": [
"# Download shutdown script files and extract to root.\n",
"# Gradient notebooks run as root, so there's no need to sudo.\n",
"!curl https://s3.amazonaws.com/ps.public.resources/tools/idle_shutdown.tgz | tar -xzv -C /"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"# Paperspace idle_shutdown.sh tool configuration\r\n",
"\r\n",
"# Time (in hours) that the system can be idle before being shut down\r\n",
"IDLE_TIME=1\r\n"
]
}
],
"source": [
"# Update idle time\n",
"# !echo \"IDLE_TIME=1\" > /etc/default/idle_shutdown\n",
"!cat /etc/default/idle_shutdown"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"expr: syntax error\r\n"
]
}
],
"source": [
"# This doesn't work\n",
"!bash /usr/local/bin/idle_shutdown.sh"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# This doesn't work\n",
"import subprocess\n",
"subprocess.call(['/usr/local/bin/idle_shutdown.sh'], cwd=\"/\")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"256"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# This doesn't work either \n",
"import os\n",
"import sys\n",
"os.system(\"bash /usr/local/bin/idle_shutdown.sh\")"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Failed to connect to bus: No such file or directory\r\n"
]
}
],
"source": [
"# This down't work either\n",
"!systemctl start idle_shutdown.service"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment