I run Biglybt as a daemon inside a screen session using the following command
screen -c /home/pi/.screenconf -L -dmS Biglybt_screen /usr/bin/java -cp "/usr/share/java/jna.jar:/home/pi/biglybt_stock/BiglyBT.jar:/home/pi/biglybt_stock/dorkbox-systemtray.jar:/home/pi/biglybt_stock/commons-cli.jar:/home/pi/biglybt_stock/log4j.jar:/home/pi/biglybt_stock/junit.jar:/home/pi/biglybt_stock/swt.jar" -Djava.library.path=/home/pi/biglybt_stock -Dbiglybt.install.path=/home/pi/biglybt_stock -Dazureus.script=/home/pi/biglybt_stock/biglybt -Djava.net.preferIPv4Stack=true -Ddebug.swtexec=1 -Dazureus.config.path=~/.biglybt_stock com.biglybt.ui.Main --ui=console
And I can stop the daemon by sending quit
command to the screen session as below
screen -S Biglybt_screen -p 0 -X stuff "quit ^M"
now I want to make a service file so that when the system shutdown the screen session gets a quit
command to be exited gracefully
I tried this service file
[Unit]
Description=BiglyBt daemon
After=network-online.target
[Service]
Type=oneshot
User=pi
RemainAfterExit=yes
ExecStart=/usr/bin/screen -c /home/pi/.screenconf -L -dmS Biglybt_screen /usr/bin/java -cp "/usr/share/java/jna.jar:/home/pi/biglybt_stock/BiglyBT.jar:/home/pi/biglybt_stock/dorkbox-systemtray.jar:/home/pi/biglybt_stock/commons-cli.jar:/home/pi/biglybt_stock/log4j.jar:/home/pi/biglybt_stock/junit.jar:/home/pi/biglybt_stock/swt.jar" -Djava.library.path=/home/pi/biglybt_stock -Dbiglybt.install.path=/home/pi/biglybt_stock -Dazureus.script=/home/pi/biglybt_stock/biglybt -Djava.net.preferIPv4Stack=true -Ddebug.swtexec=1 -Dazureus.config.path=~/.biglybt_stock com.biglybt.ui.Main --ui=console
ExecStop=/usr/bin/screen -S Biglybt_screen -p 0 -X stuff "quit ^M"
[Install]
WantedBy=multi-user.target
but when I stop the service, the process just gets killed instead of ending the screen session, So what am I missing?
UPDATE: This service file works
[Unit]
Description=BiglyBt daemon
After=network-online.target
[Service]
Environment=DISPLAY=0.0
Type=simple
User=pi
Group=pi
ExecStart=/usr/bin/java -cp "/home/pi/biglybt_stock/BiglyBT.jar:/home/pi/biglybt_stock/swt.jar" -Djava.library.path=/home/pi/biglybt_stock -Dbiglybt.install.path=/home/pi/biglybt_stock -Dazureus.script=/home/pi/biglybt_stock/biglybt -Dazureus.config.path=/home/pi/.biglybt_stock -Dazureus.overridelog=1 -Dazureus.overridelogdir=/home/pi/biglybtlogs/ -Ddebug.swtexec=1 com.biglybt.ui.Main --ui="console,telnet"
ExecStop=/usr/bin/java -cp /home/pi/biglybt_stock/BiglyBT.jar -Djava.library.path=/home/pi/biglybt_stock -Dbiglybt.install.path=/home/pi/biglybt_stock -Dazureus.script=/home/pi/biglybt_stock/biglybt -Dazureus.config.path=/home/pi/.biglybt_stock com.biglybt.ui.Main --shutdown
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
The problem now is that i can no longer start the swt ui(gui) of biglybt.
The swt ui can be started either by telneting to the server and issue ui swt
or running
/usr/bin/java -cp "/home/pi/biglybt_stock/BiglyBT.jar:/home/pi/biglybt_stock/swt.jar" -Djava.library.path=/home/pi/biglybt_stock -Dbiglybt.install.path=/home/pi/biglybt_stock -Dazureus.script=/home/pi/biglybt_stock/biglybt -Dazureus.config.path=/home/pi/.biglybt_stock -Dazureus.overridelog=1 -Dazureus.overridelogdir=/home/pi/biglybtlogs/ -Ddebug.swtexec=1 com.biglybt.ui.Main --ui="swt" --open
which will send request to the main process to start the swt ui. Unfortunately this runs fine inside regular terminal window but when running the main process inside systemd then this give
Unable to init server: Could not connect: Connection refused
inside the journal logs