Cuberite Forum
Why does a systemd unit immediately closes upon start? - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Cuberite (https://forum.cuberite.org/forum-4.html)
+--- Forum: Discussion (https://forum.cuberite.org/forum-5.html)
+--- Thread: Why does a systemd unit immediately closes upon start? (/thread-3202.html)



Why does a systemd unit immediately closes upon start? - WoJ - 08-21-2018

Hello everyone,

I just installed my first Cuberite server and wanted to configure its startup. Being on an Ubuntu 18.04, I creted a simple systemd service unit to start it:


Code:
[Unit]
Description=Cuberite server
Wants=network-online.target
After=network-online.target

[Service]
WorkingDirectory=/root/Server
ExecStart=/root/Server/Cuberite

[Install]
WantedBy=multi-user.target

This service successfuly starts and immediately successfuly shuts down, without any error message


Code:
Aug 20 19:16:30 minecraft-cuberite Cuberite[3050]: Log: [19:16:29] --- Started Log ---
Aug 20 19:16:30 minecraft-cuberite Cuberite[3050]: Log: [19:16:29] Cuberite Jenkins clang x64 Release (master) build id:
Aug 20 19:16:30 minecraft-cuberite Cuberite[3050]: Log: [19:16:29] from commit id: 89017dfbbcb0750c07fe067f2b61cde94e4dc8
Aug 20 19:16:30 minecraft-cuberite Cuberite[3050]: Log: [19:16:29] Creating new server instance...
Aug 20 19:16:30 minecraft-cuberite Cuberite[3050]: Log: [19:16:29] Reading server config...
Aug 20 19:16:30 minecraft-cuberite Cuberite[3050]: Log: [19:16:29] Starting server...
Aug 20 19:16:30 minecraft-cuberite Cuberite[3050]: Info: [19:16:29] Compatible clients: 1.8.x, 1.9.x, 1.10.x, 1.11.x, 1.1
Aug 20 19:16:30 minecraft-cuberite Cuberite[3050]: Info: [19:16:29] Compatible protocol versions 47, 107, 108, 109, 110,
Aug 20 19:16:30 minecraft-cuberite Cuberite[3050]: Warning: [19:16:29] WebServer: The server will run in unsecured HTTP m
Aug 20 19:16:30 minecraft-cuberite Cuberite[3050]: Info: [19:16:29] Put a valid HTTPS certificate in file 'webadmin/https
Aug 20 19:16:30 minecraft-cuberite Cuberite[3050]: Log: [19:16:29] Loaded 755 crafting recipes
Aug 20 19:16:30 minecraft-cuberite Cuberite[3050]: Log: [19:16:29] Loaded 67 furnace recipes and 66 fuels
Aug 20 19:16:30 minecraft-cuberite Cuberite[3050]: Log: [19:16:29] Loaded 88 brewing recipes
Aug 20 19:16:30 minecraft-cuberite Cuberite[3050]: Log: [19:16:29] -- Loading Plugins --
Aug 20 19:16:30 minecraft-cuberite Cuberite[3050]: Log: [19:16:29] Initialised Core v.15
Aug 20 19:16:30 minecraft-cuberite Cuberite[3050]: Log: [19:16:29] Initialized ChatLog v.3
Aug 20 19:16:30 minecraft-cuberite Cuberite[3050]: Log: [19:16:29] [WorldEdit] Enabling WorldEdit v0.1.12
Aug 20 19:16:30 minecraft-cuberite Cuberite[3050]: Log: [19:16:29] -- Loaded 3 Plugins --
Aug 20 19:16:30 minecraft-cuberite Cuberite[3050]: Info: [19:16:29] Your WorldEdit plugin is up-to-date
Aug 20 19:16:30 minecraft-cuberite Cuberite[3050]: Warning: [19:16:30] World "world_the_end": Did not find an acceptable
Aug 20 19:16:30 minecraft-cuberite Cuberite[3050]: Info: [19:16:30] WebAdmin is running on port(s) 8080
Aug 20 19:16:30 minecraft-cuberite Cuberite[3050]: Log: [19:16:30] Startup complete, took 895ms!
Aug 20 19:16:30 minecraft-cuberite Cuberite[3050]: Log: [19:16:30] Shutting down server...
Aug 20 19:16:30 minecraft-cuberite Cuberite[3050]: Log: [19:16:30] Unloading worlds...
Aug 20 19:16:30 minecraft-cuberite Cuberite[3050]: Log: [19:16:30] [WorldEdit] Disabling WorldEdit v0.1.12
Aug 20 19:16:30 minecraft-cuberite Cuberite[3050]: Log: [19:16:30] Disabled Core!
Aug 20 19:16:30 minecraft-cuberite Cuberite[3050]: Log: [19:16:30] Cleaning up...
Aug 20 19:16:30 minecraft-cuberite Cuberite[3050]: Log: [19:16:30] Shutdown successful!
Aug 20 19:16:30 minecraft-cuberite Cuberite[3050]: Log: [19:16:30] --- Stopped Log ---


I fixed that somehow by using the forking version:


Code:
[Unit]
Description=Cuberite server
Wants=network-online.target
After=network-online.target

[Service]
Type=forking
WorkingDirectory=/root/Server
ExecStart=/root/Server/Cuberite --service

[Install]
WantedBy=multi-user.target

This is however not a good solution, mostly because systemd works best when the service is in the foreground (it also helps with logs). So I really would like to come back to my initial solution (a service of type simple - per my first unit file).

What is special in the way Cuberite starts so that it immediately shuts down in my case above? Is it the lack of shell? Of tty? Or something else?
Can this be fixed by starting it in a specific way?


RE: Why does a systemd unit immediately closes upon start? - bearbin - 08-21-2018

Cuberite will terminate if stdin is not present unless the -d flag is used. The github issue has some more information, but not any real solutions for your use case.


RE: Why does a systemd unit immediately closes upon start? - WoJ - 08-21-2018

(08-21-2018, 05:07 AM)bearbin Wrote: Cuberite will terminate if stdin is not present unless the -d flag is used. The github issue has some more information, but not any real solutions for your use case.

Thank you, I commented out on the GitHub issue - this will become a problem when more people use systemd (in the better - non-forking - way)