Automatically stop nVidia graphics even if the application script nvrun gets SIGTERM signal.

This commit is contained in:
Kolan Sh 2011-12-25 01:34:49 +03:00
parent f5ccd68db6
commit a44e4e2e87
4 changed files with 64 additions and 12 deletions

View File

@ -14,7 +14,9 @@ start() {
! ps -p `cat $PIDFILE 2>&1` > /dev/null 2>&1 || eend -1 ! ps -p `cat $PIDFILE 2>&1` > /dev/null 2>&1 || eend -1
export LD_LIBRARY_PATH=/usr/lib/opengl/nvidia/lib:/usr/lib/opengl/nvidia/lib export LD_LIBRARY_PATH=/usr/lib/opengl/nvidia/lib:/usr/lib/opengl/nvidia/lib
start-stop-daemon --start --quiet --background --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS start-stop-daemon --start --quiet --background --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS
eend $? status=$?
(snail.autostop &>/dev/null)&
eend $status
} }
stop() { stop() {

0
etc/local.d/snail.start Normal file → Executable file
View File

View File

@ -1,15 +1,23 @@
#!/bin/sh #!/bin/sh
LOCK_FILE=/tmp/.snail.nvrun.lock LOCK_FILE=/tmp/.snail.nvrun.lock
NVRUN=/usr/local/bin/nvrun
( (
for i in `seq 8`; do
flock -n 9 flock -n 9
if [ 0 -ne $? ]; then if [[ 0 -ne $? && 5 -eq $i ]]; then
echo "Cann't lock $COUNT_FILE. Exiting..." echo "Cann't lock $COUNT_FILE. Exiting..."
exit -1 exit -1
elif [ 0 -eq $? ]; then
break
fi fi
sleep 1
done
snail.nvstat || snail.nvon snail.nvstat || snail.nvon
if [ 0 -ne $? ]; then if [ 0 -ne $? ]; then
@ -22,14 +30,21 @@ LOCK_FILE=/tmp/.snail.nvrun.lock
snail.nvrun "$@" snail.nvrun "$@"
( (
for i in `seq 8`; do
flock -n 9 flock -n 9
if [ 0 -ne $? ]; then if [[ 0 -ne $? && 5 -eq $i ]]; then
echo "Cann't lock $COUNT_FILE. Exiting..." echo "Cann't lock $COUNT_FILE. Exiting..."
exit -1 exit -1
elif [ 0 -eq $? ]; then
break
fi fi
pgrep snail.nvrun &>/dev/null sleep 1
done
pgrep -f $NVRUN &>/dev/null
if [ 0 -eq $? ]; then if [ 0 -eq $? ]; then
echo "Other applications still use nVidia chip. So we aren't switching off it, just exiting..." echo "Other applications still use nVidia chip. So we aren't switching off it, just exiting..."

35
usr/local/sbin/snail.autostop Executable file
View File

@ -0,0 +1,35 @@
#!/bin/sh
LOCK_FILE=/tmp/.snail.nvrun.lock
NVRUN=/usr/local/bin/nvrun
while [ 1 ]; do
pgrep -f $NVRUN &>/dev/null
if [ 0 -ne $? ]; then
(
for i in `seq 16`; do
flock -n 9
if [[ 0 -ne $? && 5 -eq $i ]]; then
echo "Cann't lock $COUNT_FILE. Exiting..."
exit -1
elif [ 0 -eq $? ]; then
break
fi
sleep 1
done
snail.nvoff
[ 0 -ne $? ] && echo "Error: Cann't switch off nVidia graphics. Exiting..." && exit -1
echo "nVidia chip powered off."
exit 0
) 9>$LOCK_FILE ; exit $?
fi
sleep 1
done