Skip to content

Commit

Permalink
Add packaging support for Systemd (for 16.04)
Browse files Browse the repository at this point in the history
Various other small packaging changes/improvements

Rename nginx to NGINX:
https://forum.nginx.org/read.php?2,255874,255879
  • Loading branch information
lukeyeager committed Sep 30, 2016
1 parent b1b9c71 commit b388284
Show file tree
Hide file tree
Showing 16 changed files with 117 additions and 52 deletions.
2 changes: 1 addition & 1 deletion digits/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


def main():
parser = argparse.ArgumentParser(description='DIGITS development server')
parser = argparse.ArgumentParser(description='DIGITS server')
parser.add_argument('-p', '--port',
type=int,
default=5000,
Expand Down
2 changes: 1 addition & 1 deletion docs/BuildDigits.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ sudo pip install -r $DIGITS_ROOT/requirements.txt

DIGITS needs to be installed to enable loading data and visualization plug-ins:
```
sudo pip install -e $DIGITS_HOME
sudo pip install -e $DIGITS_ROOT
```

# Starting the server
Expand Down
2 changes: 1 addition & 1 deletion packaging/deb/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RUN apt-get update \
lintian \
&& rm -rf /var/lib/apt/lists/*

ENV DEBFULLNAME "DIGITS Development Team"
ENV DEBFULLNAME "NVIDIA CORPORATION"
ENV DEBEMAIL "digits@nvidia.com"
ENV DEB_BUILD_OPTIONS nocheck

Expand Down
78 changes: 54 additions & 24 deletions packaging/deb/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
set -e

LOCAL_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
DIGITS_ROOT=$(dirname "$(dirname "$LOCAL_DIR")")
cd $DIGITS_ROOT
TARBALL_DIR="${LOCAL_DIR}/tarball/"
SRC_DIR=$(dirname "$(dirname "$LOCAL_DIR")")
cd $SRC_DIR

################################################################################
### Check for basic requirements
################################################################################

if ! which git >/dev/null 2>&1; then
echo "git not installed"
Expand All @@ -14,8 +17,8 @@ if ! git rev-parse >/dev/null 2>&1; then
echo "not a git repository"
exit 1
fi
if [ "$(git rev-parse --show-toplevel)" != "$DIGITS_ROOT" ]; then
echo "$DIGITS_ROOT is not a git repository"
if [ "$(git rev-parse --show-toplevel)" != "$SRC_DIR" ]; then
echo "$SRC_DIR is not a git repository"
exit 1
fi
if ! which python >/dev/null 2>&1; then
Expand All @@ -26,41 +29,68 @@ if ! git diff-index --quiet HEAD >/dev/null 2>&1; then
echo "git index is dirty - either stash or commit your changes"
exit 1
fi
MODULE_VERSION=$(python -c "execfile('${DIGITS_ROOT}/digits/version.py'); print __version__")
if ! which docker >/dev/null 2>&1; then
echo "docker not installed"
exit 1
fi

################################################################################
# Read envvars
################################################################################

if [ -z "$DEBIAN_REVISION" ]; then
echo ">>> Using default DEBIAN_REVISION (set the envvar to override)"
DEBIAN_REVISION=1
fi
echo "DEBIAN_REVISION: $DEBIAN_REVISION"

################################################################################
# Calculate versions
################################################################################

MODULE_VERSION=$(python -c "execfile('${SRC_DIR}/digits/version.py'); print __version__")
echo MODULE_VERSION: $MODULE_VERSION
GIT_TAG=v${MODULE_VERSION}
if [ $(git tag -l $GIT_TAG | wc -l) -ne 1 ]; then
echo "$GIT_TAG is not a git tag"
exit 1
fi
DESCRIBE_VERSION=$(git describe --match $GIT_TAG)
SOURCE_VERSION=${DESCRIBE_VERSION:1}
UPSTREAM_VERSION=$(echo $SOURCE_VERSION | sed '0,/-/{s/-/~/}' | sed 's/-/\./g')
UPSTREAM_VERSION=${DESCRIBE_VERSION:1}
if [[ "$GIT_TAG" == *"-"* ]]; then
# Replace the first dash with a tilde
UPSTREAM_VERSION=$(echo $UPSTREAM_VERSION | sed '0,/-/{s/-/~/}')
fi
# Replace the first dash with a plus
UPSTREAM_VERSION=$(echo $UPSTREAM_VERSION | sed '0,/-/{s/-/\+/}')
# Replace all dashes with dots
UPSTREAM_VERSION=$(echo $UPSTREAM_VERSION | sed 's/-/\./g')
echo UPSTREAM_VERSION: $UPSTREAM_VERSION
DEBIAN_VERSION=${UPSTREAM_VERSION}-${DEBIAN_REVISION}
echo DEBIAN_VERSION: $DEBIAN_VERSION

################################################################################
# Create source tarball
################################################################################

TARBALL_DIR="${LOCAL_DIR}/tarball/"
rm -rf $TARBALL_DIR
mkdir -p $TARBALL_DIR
git archive --prefix "digits/" -o $TARBALL_DIR/digits_${UPSTREAM_VERSION}.orig.tar.gz HEAD
git archive --prefix "digits/" -o $TARBALL_DIR/digits.orig.tar.gz HEAD

DEBIAN_REVISION=${DEBIAN_REVISION:-1}
echo DEBIAN_REVISION: $DEBIAN_REVISION
DEBIAN_VERSION=${UPSTREAM_VERSION}-${DEBIAN_REVISION}
echo DEBIAN_VERSION: $DEBIAN_VERSION
################################################################################
# Build
################################################################################

if ! which docker >/dev/null 2>&1; then
echo "docker not installed"
exit 1
fi
DOCKER_ID="digits-debbuild"
cd $LOCAL_DIR
docker build -t $DOCKER_ID \
DOCKER_BUILD_ID="digits-debuild"
docker build -t $DOCKER_BUILD_ID \
--build-arg UPSTREAM_VERSION=$UPSTREAM_VERSION \
--build-arg DEBIAN_VERSION=$DEBIAN_VERSION \
.

docker ps -a -f "name=${DOCKER_ID}" -q | xargs -r docker rm
docker create --name=$DOCKER_ID $DOCKER_ID
docker ps -a -f "name=${DOCKER_BUILD_ID}" -q | xargs -r docker rm
docker create --name=$DOCKER_BUILD_ID $DOCKER_BUILD_ID
rm -rf dist/
docker cp $DOCKER_ID:/dist .
docker rm $DOCKER_ID
docker cp $DOCKER_BUILD_ID:/dist .
docker rm $DOCKER_BUILD_ID
find `pwd`/dist/ -type f | sort
6 changes: 3 additions & 3 deletions packaging/deb/extras/custom_http_errors/413.shtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<html>
<title>File too large</title>
<title>Failed to upload file</title>
<body>
<h1>Error - File upload too large</h1>
<h1>Error: File upload too large</h1>
<p>
You attempted to upload a file that exceeded the limit allowed by the
NGINX reverse proxy server.
Expand All @@ -13,7 +13,7 @@ You can try uploading your file directly to the DIGITS server running at
</p>
<p>
You can also try increasing the value of the client_max_body_size setting
in /etc/nginx/sites-available/digits.site.
in /etc/nginx/sites-available/digits.nginx-site.
</p>
</body>
</html>
37 changes: 30 additions & 7 deletions packaging/deb/extras/custom_http_errors/502.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,41 @@
<html>
<title>Failed to connect to DIGITS</title>
<body>
<h1>Error: Unable to connect to NVIDIA DIGITS</h1>
<h1>Error: Unable to connect to DIGITS</h1>

<h3>Restart the server</h3>
<p>
To fix this problem, try stopping and restarting the DIGITS server by running
the following two commands:
On Ubuntu 14.04, use this command to restart the server:
</p>
<pre>
sudo stop digits
sudo start digits
sudo service digits restart
</pre>
<p>
If you are still encountering problems after attempting to restart the DIGITS
server, check /var/log/digits/digits.log for errors.
On Ubuntu 16.04, use this command to restart the server:
</p>
<pre>
sudo systemctl restart digits
</pre>

<h3>Check the logs for errors</h3>
<p>
If you are still encountering problems after restarting, check the logs for errors.
</p>
<pre>
cat /var/log/digits/digits.log
</pre>
</p>
<p>
For additional messsages on Ubuntu 14.04:
</p>
<pre>
cat /var/log/upstart/digits.log
</pre>
<p>
For additional messages on Ubuntu 16.04:
</p>
<pre>
journalctl -u digits.service
</pre>
</body>
</html>
2 changes: 1 addition & 1 deletion packaging/deb/extras/digits.nginx-site
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# DIGITS nginx site
# DIGITS NGINX site

server {
listen 80; #AUTOCONFIG port (DO NOT DELETE THIS LINE)
Expand Down
2 changes: 1 addition & 1 deletion packaging/deb/templates/control
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Maintainer: #USERNAME# <#EMAIL#>
Homepage: https://developer.nvidia.com/digits
Vcs-Browser: https://github.com/NVIDIA/DIGITS
Priority: optional
Build-Depends: debhelper (>= 9), dh-python, python-all, python-setuptools, debconf
Build-Depends: debhelper (>= 9), dh-python, dh-systemd, python-all, python-setuptools, debconf
Standards-Version: #POLICY#

Package: digits
Expand Down
4 changes: 2 additions & 2 deletions packaging/deb/templates/copyright
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ Upstream-Name: #PACKAGE#
Source: https://github.com/NVIDIA/DIGITS

Files: *
Copyright: #YEAR# #USERNAME# <#EMAIL#>
Copyright: #YEAR# NVIDIA CORPORATION
License: BSD-3-Clause

Files: debian/*
Copyright: #YEAR# #USERNAME# <#EMAIL#>
Copyright: #YEAR# NVIDIA CORPORATION
License: BSD-3-Clause

License: BSD-3-Clause
Expand Down
2 changes: 0 additions & 2 deletions packaging/deb/templates/digits.default

This file was deleted.

4 changes: 2 additions & 2 deletions packaging/deb/templates/digits.postinst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ case "$1" in
# Update permissions on new directories
chown www-data /var/lib/digits/jobs /var/log/digits

# Disable default nginx site
# Disable default NGINX site
NGINX_NEEDS_RELOAD=false
DEFAULT_SITE=/etc/nginx/sites-enabled/default
if [ -L "$DEFAULT_SITE" ]
Expand All @@ -26,7 +26,7 @@ case "$1" in

# Enable nginx site
SITE_FILE=/etc/nginx/sites-available/digits.nginx-site
SITE_LINK=/etc/nginx/sites-enabled/digits.site
SITE_LINK=/etc/nginx/sites-enabled/digits.nginx-site
if [ "$PORT" != "-1" ]
then
sed "s/.*AUTOCONFIG port.*/ listen ${PORT}; #AUTOCONFIG port (DO NOT DELETE THIS LINE)/" $SITE_FILE -i
Expand Down
4 changes: 2 additions & 2 deletions packaging/deb/templates/digits.prerm
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ set -e

case "$1" in
remove)
# Disable nginx site
SITE_LINK=/etc/nginx/sites-enabled/digits.site
# Disable NGINX site
SITE_LINK=/etc/nginx/sites-enabled/digits-nginx.site
if [ -L "$SITE_LINK" ]
then
rm -f $SITE_LINK
Expand Down
15 changes: 15 additions & 0 deletions packaging/deb/templates/digits.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# DIGITS systemd service
[Unit]
Description=DIGITS server
After=local-fs.target network.target

[Service]
User=www-data
Environment="DIGITS_JOBS_DIR=/var/lib/digits/jobs"
Environment="DIGITS_LOGFILE_FILENAME=/var/log/digits/digits.log"
ExecStart=/usr/bin/python -m digits -p 34448
Restart=on-failure
ExecStop=/bin/kill -INT $MAINPID

[Install]
WantedBy=multi-user.target
6 changes: 3 additions & 3 deletions packaging/deb/templates/digits.templates
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Template: digits/port
Type: string
Default: 80
Description: DIGITS front-end port for nginx reverse proxy (0-65535):
Description: DIGITS front-end port for NGINX reverse proxy (0-65535):
The DIGITS backend server runs on port 34448 (DIGIT), but this package also
configures nginx to function as a reverse proxy for DIGITS.
configures NGINX to function as a reverse proxy for DIGITS.
.
If you don't want to use nginx as a reverse proxy, choose "-1" and the nginx
If you don't want to use NGINX as a reverse proxy, choose "-1" and the NGINX
site will not be installed.

Template: digits/port-invalid
Expand Down
2 changes: 1 addition & 1 deletion packaging/deb/templates/rules
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/make -f

%:
dh $@ --parallel --with=python2 --buildsystem=pybuild
dh $@ --parallel --with=python2,systemd --buildsystem=pybuild

1 change: 0 additions & 1 deletion packaging/deb/templates/source/format

This file was deleted.

0 comments on commit b388284

Please sign in to comment.