Skip to content

Instantly share code, notes, and snippets.

@linuxluser
Last active March 31, 2017 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linuxluser/fe14eef12e548029af5684cb5adebf51 to your computer and use it in GitHub Desktop.
Save linuxluser/fe14eef12e548029af5684cb5adebf51 to your computer and use it in GitHub Desktop.
#!/bin/sh
### BEGIN INIT INFO
# Provides: nvidia-docker
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: A Docker plugin that brings Nvidia support to containers
# Description: A Docker plugin that brings Nvidia support to containers
### END INIT INFO
LOGFILE=/var/log/nvidia-docker.log
ERRORFILE=/var/log/nvidia-docker.err
PIDFILE=/var/run/nvidia-docker.pid
start() {
local pid
/usr/bin/nvidia-docker-plugin >>$LOGFILE 2>>$ERRORFILE
pid=$(pidof -s nvidia-docker-plugin || true)
if [ -z "$pid" ]; then
echo "Failed to start - check $ERRORFILE for details" >&2
exit 1
fi
echo $pid >$PIDFILE
}
stop() {
local force
force=$1
PID=$(cat $PIDFILE)
if [ -z "PID" ]; then
return
fi
if [ $force ]; then
kill -9 $PID
else
kill $PID
fi
rm -f $PIDFILE
}
status() {
local pid
pid=$(pidof -s nvidia-docker-plugin || true)
if [ -n "$pid" ]; then
echo "Running as process $pid"
else
echo "Not running"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
force-reload)
stop true
start
;;
status)
status
;;
*)
echo "Usage: service nvidia-docker {start|stop|restart|status}"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment