Skip to content

Instantly share code, notes, and snippets.

@SchapplM
Created January 29, 2017 20:26
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 SchapplM/65767fe4fbbe20fc479de9a273faaaa5 to your computer and use it in GitHub Desktop.
Save SchapplM/65767fe4fbbe20fc479de9a273faaaa5 to your computer and use it in GitHub Desktop.
JDownloader 2 as a Linux SysVInit daemon in a virtual display with VNC Server
#! /bin/sh -ex
### BEGIN INIT INFO
# Provides: JDownloader 2
# Required-Start: $x11-common
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start and stop JDownloader 2
# Description: With this script you are able to run JDownloader 2 as deamon.
### END INIT INFO
# Author: Moritz Schappler <moritz-schappler@web.de>
# Sources:
# [1] Jonas Lehmke <jonas@3jo.de> https://forum.ubuntuusers.de/topic/howto-jdownloader-2-beta-auf-ubuntu-server/#post-6706552
# [2] https://gist.github.com/dmitriy-kiriyenko/974392
NAME="jd2window"
USER=jd
RUNDIR=/var/run/$NAME
PIDFILE1=$RUNDIR/xvfb.pid
PIDFILE2=$RUNDIR/openbox.pid
PIDFILE3=$RUNDIR/jd2.pid
DAEMON1=/usr/bin/Xvfb
DAEMON1_OPTS=":1 -screen 0 1024x768x24"
DAEMON2=/usr/bin/openbox-session
DAEMON2_OPTS=""
DAEMON3=/usr/local/jd2/JDownloader2
DAEMON3_OPTS=""
mkdir -p $RUNDIR
chown -R $USER $RUNDIR
# Aktionen
case "$1" in
start)
echo "Starting JD2 in Openbox WindowManager in Xvfb Display"
if test -e $PIDFILE1 ; then
echo "$DAEMON1 already running (PID-File $PIDFILE1 exists). Try restart instead"
exit 1
else
start-stop-daemon --start --chuid $USER --background --make-pidfile --pidfile "$PIDFILE1" --exec "$DAEMON1" -- $DAEMON1_OPTS &
echo "started $DAEMON1"
sleep 2
fi
export DISPLAY=:1
if test -e $PIDFILE2 ; then
echo "$DAEMON2 already running (PID-File $PIDFILE2 exists). Try restart instead"
exit 1
else
start-stop-daemon --start --chuid $USER --background --make-pidfile --pidfile "$PIDFILE2" --exec "$DAEMON2" -- $DAEMON2_OPTS
echo "started $DAEMON2"
sleep 2
fi
if test -e $PIDFILE3 ; then
echo "$DAEMON3 already running (PID-File $PIDFILE3 exists). Try restart instead"
exit 1
else
start-stop-daemon --start --chuid $USER --background --make-pidfile --pidfile "$PIDFILE3" --exec "$DAEMON3" -- $DAEMON3_OPTS
fi
;;
stop)
echo "Stopping JD2 in Openbox WindowManager in Xvfb Display"
start-stop-daemon --stop --chuid $USER --pidfile "$PIDFILE3"
test -e $PIDFILE3 && rm $PIDFILE3
echo "stopped $DAEMON3"
start-stop-daemon --stop --chuid $USER --pidfile "$PIDFILE2"
test -e $PIDFILE2 && rm $PIDFILE2
echo "stopped $DAEMON2"
start-stop-daemon --stop --chuid $USER --pidfile "$PIDFILE1"
test -e $PIDFILE1 && rm $PIDFILE1
echo "stopped $DAEMON1"
;;
restart)
$0 stop
$0 start
;;
esac
exit 0
[Unit]
Description=Start x11vnc at startup (display 1).
After=multi-user.target
[Service]
Type=forking
ExecStart=/usr/bin/x11vnc -auth /var/run/lightdm/root/:0 -display :1 -rfbauth /etc/x11vnc.pass -rfbport 5901 -rfbportv6 5901 -noxrecord -noxfixes -noxdamage -forever -bg -o /var/log/x11vnc_jdwindow.log
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment