Just need to run them on startup. Systemd
Solution 1
First recheck if the exact same command is running in terminal. Then remember that if the service fails it sometimes does not restart immediately but sometimes waits a time. So restarting every few seconds is going to give trouble. If there are too many failures within a certain time the service is stopped permanently.
All this is configured in the Unit section and all this im sure you know already. Therefore I'll give you an example of a working Unit section that has some surprises if you look at it carefully.
[Unit]
Description=Radmon service
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=30
User=marc
ExecStart=/usr/bin/python -u /home/marc/GMC/pyradmon.py
StandardOutput=null
StandardError=inherit
[Install]
WantedBy=multi-user.target
I am sure this will help. (Hint! Sec= )
Solution 2
You have Active: failed (Result: protocol)
and (code=exited, status=0/SUCCESS)
, which suggest you're running a background process in the systemd exec command.
If you run your screen
command on a console, does it put itself in background? That should explain it.
Try using Type=forking
, that should solve it.
Alternatively, run your screen
command in foreground, though "attaching" might not work as expected, since a systemd unit is running without a terminal, so screen might fail at that... Perhaps Type=forking
is the best way to solve this one here...
Andry Kritsun
Updated on September 18, 2022Comments
-
Andry Kritsun over 1 year
Ubuntu 19.04 Hi, I have a bug with systemd I have a launch-server.service file that has
[Unit] Description=LaunchServer After=network.target [Service] WorkingDirectory=/home/aborigen/Launcher/LaunchServer/build/libs Type=notify User=aborigenserver Group=sudo NotifyAccess=all Restart=always ExecStart=/usr/bin/screen -DmS launchserver /usr/java/jdk1.8.0_221/bin/java -Xmx128M -javaagent:LaunchServer.jar -jar LaunchServer.jar ExecStop=/usr/bin/screen -p 0 -S launchserver -X eval 'stuff "stop"\015' [Install] WantedBy=multi-user.target
The algorithm of my actions is as follows:
- aborigen@aborigenserver:/etc/systemd/system$
sudo nano launch-server.service
thereby creating this file and pasting the parameters above
- aborigen@aborigenserver:/etc/systemd/system$
sudo systemctl daemon-reload
- aborigen@aborigenserver:/etc/systemd/system$
sudo systemctl status launch-server.service
and in response:
● launch-server.service - LaunchServer Lost Paradise
Loaded: loaded (/etc/systemd/system/launch-server.service; disabled; vendor preset: enabled)
Active: inactive (dead)- aborigen@aborigenserver:/etc/systemd/system$
sudo systemctl enable launch-server.service
Created symlink /etc/systemd/system/multi-user.target.wants/launch-server.service → /etc/systemd/system/launc h-server.service.
- aborigen@aborigenserver:/etc/systemd/system$
sudo systemctl status launch-server.service
● launch-server.service - LaunchServer Lost Paradise
Loaded: loaded (/etc/systemd/system/launch-server.service; enabled; vendor preset: enabled) Active: inactive (dead)- aborigen@aborigenserver:/etc/systemd/system$
sudo systemctl start launch-server.service
Job for launch-server.service failed because the service did not take the steps required by its unit configuration. See "systemctl status launch-server.service" and "journalctl -xe" for details.
- aborigen@aborigenserver:/etc/systemd/system$
sudo systemctl status launch-server.service
aborigen@aborigenserver:/etc/systemd/system$ sudo systemctl status launch-server.service
● launch-server.service - LaunchServer Lost Paradise Loaded: loaded (/etc/systemd/system/launch-server.service; enabled; vendor preset: enabled) Active: failed (Result: protocol) since Mon 2019-07-29 12:45:50 EEST; 2h 49min ago Main PID: 2496 (code=exited, status=0/SUCCESS) июл 29 12:45:50 aborigenserver systemd[1]: launch-server.service: Service RestartSec=100ms expired, scheduling restart. июл 29 12:45:50 aborigenserver systemd[1]: launch-server.service: Scheduled restart job, restart counter is at 5. июл 29 12:45:50 aborigenserver systemd[1]: Stopped LaunchServer Lost Paradise. июл 29 12:45:50 aborigenserver systemd[1]: launch-server.service: Start request repeated too quickly. июл 29 12:45:50 aborigenserver systemd[1]: launch-server.service: Failed with result 'protocol'. июл 29 12:45:50 aborigenserver systemd[1]: Failed to start LaunchServer Lost Paradise. aborigen@aborigenserver:/etc/systemd/system$ chmod +x /home/aborigen/Server/start.sh aborigen@aborigenserver:/etc/systemd/system$ sudo systemctl start start-server.service aborigen@aborigenserver:/etc/systemd/system$ sudo systemctl reload start-server.service Failed to reload start-server.service: Job type reload is not applicable for unit start-server.service.
- aborigen@aborigenserver:/etc/systemd/system$
journalctl -xe
eventually:
-- Назначен автоматический перезапуск юнита launch-server.service, так как для него был задан -- параметр Restart=. июл 29 12:45:50 aborigenserver systemd[1]: Stopped LaunchServer Lost Paradise. -- Subject: Завершена остановка юнита launch-server.service. -- Defined-By: systemd -- Support: http://www.ubuntu.com/support -- -- Процесс остановки юнита launch-server.service был завершен. июл 29 12:45:50 aborigenserver systemd[1]: launch-server.service: Start request repeated too quickly. июл 29 12:45:50 aborigenserver systemd[1]: launch-server.service: Failed with result 'protocol'. -- Subject: Unit failed -- Defined-By: systemd -- Support: http://www.ubuntu.com/support -- -- The unit launch-server.service has entered the 'failed' state with result 'protocol'. июл 29 12:45:50 aborigenserver systemd[1]: Failed to start LaunchServer Lost Paradise. -- Subject: Ошибка юнита launch-server.service -- Defined-By: systemd -- Support: http://www.ubuntu.com/support -- -- Произошел сбой юнита launch-server.service. -- -- Результат: failed.
I also have start-server.service
[Unit] Description=Lost Paradise Server After=network.target After=launch-server.service [Service] WorkingDirectory=/home/aborigen/Server/ User=aborigenserver Group=sudo Restart=always ExecStart=/home/aborigen/Server/start.sh ExecStop=/usr/bin/screen -p 0 -S ServerAstrey -X eval 'stuff "stop"\015' [Install] WantedBy=multi-user.target
which accordingly:
aborigen@aborigenserver:/etc/systemd/system$ sudo
systemctl status start-server.service
● start-server.service - Lost Paradise Server Loaded: loaded (/etc/systemd/system/start-server.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Mon 2019-07-29 15:39:26 EEST; 20min ago Process: 3427 ExecStart=/home/aborigen/Server/start.sh (code=exited, status=1/FAILURE) Main PID: 3427 (code=exited, status=1/FAILURE) июл 29 15:39:26 aborigenserver systemd[1]: start-server.service: Service RestartSec=100ms expired, scheduling restart. июл 29 15:39:26 aborigenserver systemd[1]: start-server.service: Scheduled restart job, restart counter is at 5. июл 29 15:39:26 aborigenserver systemd[1]: Stopped Lost Paradise Server. июл 29 15:39:26 aborigenserver systemd[1]: start-server.service: Start request repeated too quickly. июл 29 15:39:26 aborigenserver systemd[1]: start-server.service: Failed with result 'exit-code'. июл 29 15:39:26 aborigenserver systemd[1]: Failed to start Lost Paradise Server.
Already the second day I pull the hair out of my head. I just need to run them on startup. Help please :)
- aborigen@aborigenserver:/etc/systemd/system$