Skip to content

Instantly share code, notes, and snippets.

@WaterSibilantFalling
Created September 21, 2017 13:57
Show Gist options
  • Save WaterSibilantFalling/52193f0df2ed6b7f89de0dc126371706 to your computer and use it in GitHub Desktop.
Save WaterSibilantFalling/52193f0df2ed6b7f89de0dc126371706 to your computer and use it in GitHub Desktop.
a script that prepares and then runs qBittorrent
#!/usr/bin/perl
# this is to perform any checks required before running qbittorrent
#
#
# do NOT recursively call this current script by mistake
use common::sense;
my $debug = 1;
my $QBITTORRENT_NOTUSED = "/usr/bin/qbittorrent"; # installed by apt
my $QBITTORRENT_REAL = "/usr/local/bin/qbittorrent"; # my compiled
# ----- check 1: are the torrenting directories mounted, there? --------------
my @checkPath = ( "/mnt/t/", "/usbhd/");
for my $checkfileRoot (@checkPath) {
if (not -f "$checkfileRoot/.amMountedCheckDir_dontRemove/_checkFile_dont_remove_") {
`xmessage \"The filesystem $checkfileRoot is not mounted properly. Exiting.\" & ` ;
exit (0);
}
}
if (`sudo pidof qbittorrent-nox`){
`xmessage "qbittorent-nox was running. Killing it first" & `;
`killall qbittorrent-nox`;
sleep 2;
`killall qbittorrent-nox`;
sleep 2;
`killall -9 qbittorrent-nox`;
sleep 2;
}
# ----- DONE: all checks passed: run qBittorrent --------------
# - get rid of any crashed or running-not-running copies (a problem)
my $qbtAlreadyRunning = `sudo pidof \$\( basename $QBITTORRENT_REAL \); sudo pidof \$\( basename $QBITTORRENT_NOTUSED \) `;
chomp $qbtAlreadyRunning;
if ($qbtAlreadyRunning) {
`killall -q $QBITTORRENT_REAL`;
`killall -q $QBITTORRENT_NOTUSED`;
sleep 2;
`killall -q -9 $QBITTORRENT_REAL`;
`killall -q -9 $QBITTORRENT_NOTUSED`;
sleep 1;
}
# try to stop qbittorrent crashing on too many files open
`ulimit -n 4000`;
# - run qbittorrent
my $exports_graphics = "export QT_X11_NO_MITSHM=1 QT_GRAPHICSSYSTEM=raster ; ";
my $exports_libs = "LD_LIBRARY_PATH=/usr/local/lib:/usr/lib/i386-linux-gnu:\$LD_LIBRARY_PATH ; ";
my $nice = "nice -n 20 "; # no sudo else as root
my $cmd = "$exports_graphics $nice $QBITTORRENT_REAL & 2>/dev/null & exit ";
print "about to run:\n$cmd\n"
if ($debug);
`$cmd`;
# NOTE: the default is set in /etc/environment
# QT_GRAPHICSSYSTEM="native" # source of my problems?
# QT_GRAPHICSSYSTEM="raster" # seemed good
# QT_GRAPHICSSYSTEM="opengl" # seemed slow
# NOTE: no reason to set the library path
sleep 1;
exit (0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment