0

Systemd startup file

Richard Leonard 4 years ago updated 4 years ago 5

For any linux folk out there... here is my latest systemd startup file....

[Unit]
Description=Ubooquity-Server
After=network.target

[Service]
WorkingDirectory=/home/rmleonard/Ubooquity
Type=forking
ExecStart=/usr/bin/screen \
-dmS uboo \
/usr/bin/java \
-Xmx6g \
-Xms5g \
-Xss1g \
-jar Ubooquity.jar \
--headless \
--host 192.168.1.53 \
--libraryport 2207 \
--adminport 2292 \
--workdir /home/rmleonard/Ubooquity \
--remoteadmin

ExecStop=/usr/bin/screen -S uboo -p 0 \
-X stuff "Q^M"

Restart=on-failure
User=rmleonard
Group=netusers
UMask=0022

[Install]
WantedBy=multi-user.target

-=-=-=-

On the ExecStop ... following the Q (but still inside the quotes) is a 'carriage return' using vi as the text editor, scroll to just past the Q, press I to enter insert mode, then do 'control-v' <return>

That should insert a highlighted ^M (which means a carriage return)

The server I'm using has 16GB of ram in it, so....

Xmx6g --- allocate 6GB ram to the java app

Xms5g --- start w/5GB pre-allocated (it may never use that last gb)

Xss1g --- allow up to 1GB for thread space (seemed like a good idea at the time) --

So... first is starts the terminal multiplexer 'screen' (you might have to install that if you haven't already)

Then it starts Java / Ubooquity in that 'bubble' ..

if it sounds complicated then it may not be what you need.

If you are running any of the Debian Linuxes (ubuntu, mint, etc.) Then this may be of use

Hi Richard,

Thanks a lot for that script.

I'm not familiar with the use of screen.

What are the benefits of using it in this case?

screen allows you to run console applications (things that like to write to the terminal screen) in the background... (kinda/sorta)...

When you run ubooquity in a terminal, it prints all sorts of stuff, and log messages, state of health, and so on... and when you are done-- you press 'q' to quit...


Screen allows you to run just like that, except, that terminal session - terminal window, can be 'backgrounded', 'hidden', etc.(and then brought back)... 

Yes, you can run as a daemon/headless and program runs in background... but you then lose the console error messages, (which can help w/identifying errors)

I like to think of it as a container (its not) ...

Rich

Thanks, that makes sense!

Morning Rich,

I am trying to apply your memory tweaks to my script however my Linux skills are a little basic and I'm not sure if I am applying them properly.

This is my normal working script:

[Unit]
Description=Ubooquity
After=network.target

[Service]
WorkingDirectory=/opt/Ubooquity
User=craftyclown
Group=craftyclown

Type=simple
ExecStart= /usr/bin/java -jar Ubooquity.jar --remoteadmin --headless
TimeoutStopSec=20
KillMode=process
Restart=on-failure

[Install]
WantedBy=multi-user.target

It works fine, however Ubooquity uses 12 gig of virtual memory, which seems to be considerably higher than anything else. With your memory adjustments it jumps to 38gig of virtual memory.  Does that sound right?

This is the new script:

[Unit]
Description=Ubooquity
After=network.target

[Service]
WorkingDirectory=/opt/Ubooquity
User=craftyclown
Group=craftyclown

Type=simple
ExecStart= /usr/bin/java -Xmx6g -Xms5g -Xss1g -jar Ubooquity.jar --remoteadmin --headless
TimeoutStopSec=20
KillMode=process
Restart=on-failure

[Install]
WantedBy=multi-user.target

Any thoughts?

Cheers

Rich

well, a few questions...

How much memory is in your system?

The second parameter is a hard allocation, the first is a limit, the last is for each thread.... so it gets complicated.. quickly.

The system I setup has 16GB of ram... and I wanted to to see how large I could set things, and NOT trigger swap.. and for me, for my system, (which also has calibre-server, qbittorrent, nfs, apache2, etc)... I will also try various settings on a 4GB server, and possibly a little raspberry pi.... just remember - the 1st number .. memory max, 2nd amount to immediately allocate, 3rd amount for each thread... also pay attention to swap.

memory commands (linux) of use.... "free", "swapon", "top/htop"... 

As you tweak and test... shoot for minimal swap use..

Does that help?