forked from notefox/OHDMWebServer
-
Notifications
You must be signed in to change notification settings - Fork 0
run as Daemon
NoteFox edited this page Jun 10, 2020
·
13 revisions
The Service is made with the Intention in mind, that it runs a long time. And the executing the jar File as a User means, that the Session, in which it has been started, needs to stay open. So If we don't want that, there are other ways to archive running it as long as the Server is actively running.
A Daemon/Service is a program that runs automatically when the computer is started and waits in the background to do its job. A service usually has no graphical user interface. To set up our "Daemon" we're gonna use our "Init-System". In most Debian-based Systems, it's called "systemd".
- make sure you got are able to use sudo!
- `cd /etc/systemd/system``
-
touch ohdm_download.service("ohdm_download" is just the name, it is changeable) - use your favourite file editor to edit the just created File (use sudo for that, since we are in a system directory)
- Add the lines:
[Unit] # Unit header
Description = OHDM Download Service for Android App # Description
After=network.target # to make sure that the Service will always be started after network connections are available
[Service] # Service Header
Type=forking # we need to set the type to forking, because we use Multi-Threading
ExecStart=bash /<ServicePath>/startServer.sh # that's the script we are starting , more on that later
Restart=always # Configures whether the service shall be restarted when the service process exits, is killed, or a timeout is reached
RestartSec=1 # Configures the time to sleep before restarting a service
User=<User> # setting the user name, under which it runs (has to be a real user name!!!)
WorkingDirectory=/<ServicePath>/ # Directory, the Service is working in
TimeoutSec=0 # Configures the time to wait for start-up and shut-down
[Install]
WantedBy=multi-user.target # sets the "wanted-by key" for multi-user system, with or without graphical login
sudo systemctl enable ohdm_download.servicesudo sudo systemctl daemon-reload- go into your Service package
- create a new File by using
touch startServer.sh - use your favourite file editor to edit the just created File
- add the Lines :
#!/bin/bash
cd /<from root ServicePath>
<java-jdk-path> -jar runner-<current version>.jar > stdOutputtxt &> errOutput.txt
sudo chmod +x startServer.sh-
sudo systemctl start ohdm_download.serviceYou know that this Command ran successfully,if nothing happens and your command line seems stuck, just exit it by pressingctl-cand your service should run fine now
if you want to know your service status, just type in
sudo systemctl status ohdm_download.service