Spuštění aplikace při startu

Založil aricak, 03. 12. 2017, 22:23:13

Předchozí téma - Další téma

aricak

Ahoj, jak mohu spusit aplikaci, (např.: Minecraft server) při startu pod jiným uživatelem. Mockrát děkuji za rady.
Debian Vydání 9 (stretch) 64-bit
VERZE OS: Jádro Linux 4.9.0-8-amd64 x86_64
MATE 1.16.2

PC Intel XEON E3 1230 3,2GHZx8
RAM 16GB
Grafická karta GeForce GT 710 PCI-e 1x

Petr Krčmář

Standardní způsob je vytvořit vlastní Unit file v adresáři /etc/systemd/service/ a v něm máš možnost nadefinovat si v sekci Service položku User.

aricak

Děkuji za odpověď, asi mi to musíte vysvětlit trochu podrobněji, koukl jsem na manual systemd a nic chytrého jsem nevyčetl zjistil jsem jen toto:

root@Phoebe:/home/jakub# systemctl status
Failed to read server status: No such interface ''


složku "SERVICE" tam nemám
mám složky NETWORK, SYSTEM, USER
a v SYSTEMD adresáři mám pár configů, kde přepisuji proměnné


Debian Vydání 9 (stretch) 64-bit
VERZE OS: Jádro Linux 4.9.0-8-amd64 x86_64
MATE 1.16.2

PC Intel XEON E3 1230 3,2GHZx8
RAM 16GB
Grafická karta GeForce GT 710 PCI-e 1x

Petr Krčmář

Tomu příkazu chybí ještě další parametr v podobě názvu nějaké služby, třeba sshd. Pak to vypíše její stav. Všechny lze získat snadno:

$ systemctl list-unit-files

Cílem je vytvořit vlastní Unit file, ve kterém se popíše, jak a kdy se má ta služba spouštět. Viz

$ ls /lib/systemd/system/*service

aricak

Mno zkusil jsem stále mi to není moc jasné... Kam, mám vytvořit soubor co v něm má být a jak to má být spuštěno pod uživatelem pokus, když jsem uživatel jakub

Díky
Debian Vydání 9 (stretch) 64-bit
VERZE OS: Jádro Linux 4.9.0-8-amd64 x86_64
MATE 1.16.2

PC Intel XEON E3 1230 3,2GHZx8
RAM 16GB
Grafická karta GeForce GT 710 PCI-e 1x

aricak

#5
Tákže, přidám soubor minecraft@.services do složky /lib/systemd/system/

s obsahem:

[Unit]
Description=Minecraft Server %i
After=network.target

[Service]
WorkingDirectory=/home/barunka/minecraft/%i
PrivateUsers=true # Users Database is not available for within the unit, only root and minecraft is available, everybody else is nobody
User=barunka
Group=barunka
ProtectSystem=full # Read only mapping of /usr /boot and /etc
ProtectHome=true # /home, /root and /run/user seam to be empty from within the unit. It is recommended to enable this setting for all long-running services (in particular network-facing ones).
ProtectKernelTunables=true # /proc/sys, /sys, /proc/sysrq-trigger, /proc/latency_stats, /proc/acpi, /proc/timer_stats, /proc/fs and /proc/irq will be read-only within the unit. It is recommended to turn this on for most services.
# Implies MountFlags=slave
ProtectKernelModules=true # Block module system calls, also /usr/lib/modules. It is recommended to turn this on for most services that do not need special file systems or extra kernel modules to work
# Implies NoNewPrivileges=yes
ProtectControlGroups=true # It is hence recommended to turn this on for most services.
# Implies MountAPIVFS=yes

ExecStart=/bin/sh -c '/usr/bin/screen -DmS mc-%i /usr/bin/java -server -Xms512M -Xmx2048M -XX:+UseG1GC -XX:+CMSIncrementalPacing -XX:+CMSClassUnloadingEnabled -XX:ParallelGCThreads=2 -XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=10 -jar $(ls -v | grep -i "FTBServer.*jar\|craftbukkit.*jar" | head -n 1) nogui4'

# nohup java -d64 -Xincgc -Xmx1024M -jar craftbukkit.jar nogui4 # tímto se spuší pod uživatelem...

ExecReload=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "reload"\\015'

ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "say SERVER SHUTTING DOWN. Saving map..."\\015'
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "save-all"\\015'
ExecStop=/usr/bin/screen -p 0 -S mc-%i -X eval 'stuff "stop"\\015'
ExecStop=/bin/sleep 10

Restart=on-failure
RestartSec=60s

[Install]
WantedBy=multi-user.target

#########
# HowTo
#########
# my to máme pod /home/barunka/minecraft
# Create a directory in /opt/minecraft/XX where XX is a name like 'survival'
# Add minecraft_server.jar into dir with other conf files for minecraft server
#
# Enable/Start systemd service
#    systemctl enable minecraft@survival
#    systemctl start minecraft@survival
#
# To run multiple servers simply create a new dir structure and enable/start it
#    systemctl enable minecraft@creative
# systemctl start minecraft@creative




Převzal jsem to odtud:
https://minecraft.gamepedia.com/Tutorials/Server_startup_script

Asi to budu ovládat službu takto:
systemctl enable minecraft@barunka
systemctl disable minecraft@barunka

Debian Vydání 9 (stretch) 64-bit
VERZE OS: Jádro Linux 4.9.0-8-amd64 x86_64
MATE 1.16.2

PC Intel XEON E3 1230 3,2GHZx8
RAM 16GB
Grafická karta GeForce GT 710 PCI-e 1x

aricak

Hm tak tohle mi nefunguje... :-(
Debian Vydání 9 (stretch) 64-bit
VERZE OS: Jádro Linux 4.9.0-8-amd64 x86_64
MATE 1.16.2

PC Intel XEON E3 1230 3,2GHZx8
RAM 16GB
Grafická karta GeForce GT 710 PCI-e 1x

aricak

Ještě jsem našel toto:
https://github.com/Ahtenus/minecraft-init
Ale fakt nevím co to udělá a jak to má fungovat.

Prosím poraďte.
Debian Vydání 9 (stretch) 64-bit
VERZE OS: Jádro Linux 4.9.0-8-amd64 x86_64
MATE 1.16.2

PC Intel XEON E3 1230 3,2GHZx8
RAM 16GB
Grafická karta GeForce GT 710 PCI-e 1x

aricak

Tak po delším kolaborování jsem to asi dal dohromady.

Citace od: aricak kdy 08. 12. 2017, 09:35:58
Ještě jsem našel toto:
https://github.com/Ahtenus/minecraft-init

Udělal jsem složku /opt/minecraf-init/
vytvořil jsem simlink v /etc/init.d/minecraft-barunka odkazující na /opt/minecraf-init/minecraft
nakofiguroval jsem config v /opt/minecraf-init/minecraft/config

Myslím si když se přejmenuje minecraft-init např na minecraft-barunka a změní se v minecraft skritpu z minecraft-init na minecraft-barunka, dalo by se rozběhnout i 2. server pod jiným uživatelem. (Což já nepotřebuji, aspoň doufám)

server se krásně ovládá přes /etc/init.d/minecraft-barunka help kde jsou všechny příkazy.


Debian Vydání 9 (stretch) 64-bit
VERZE OS: Jádro Linux 4.9.0-8-amd64 x86_64
MATE 1.16.2

PC Intel XEON E3 1230 3,2GHZx8
RAM 16GB
Grafická karta GeForce GT 710 PCI-e 1x