0

I have a very ( seemingly ) simple question, of how to keep an x86_64 application "alive" on an Ubuntu server. Initially and through great effort ( I am very inexperienced with Ubuntu/Linux), I was able to have it boot on startup, however the application seems to "die" every once in a while anyway.

I attempted to make the application into a service, like so:

[Unit]
Description=runs the mmo
After=multi-user.target

[Service]
Type=oneshot
ExecStart=/root/mmo/MMO.x86_64
Restart=on-failure

[Install]
WantedBy=multi-user.target

and uploaded it via ftp to "/etc/systemd/system" on my server and set the permissions to 777, however the file I uploaded ( the icon) looks different from the other .service files so I think I did something wrong

link to screenshot of file on server

( it looks like a text document, while the other ones look like like shortcuts to folders , even though I named mine .service also)

what am I doing wrong? thanks in advance

root@server1:~# systemctl status mmo * mmo.service - runs the mmo Loaded: error (Reason: Invalid argument) Active: failed (Result: signal) since Thu 2018-01-04 02:48:53 UTC; 2 days ago Main PID: 757 (code=killed, signal=KILL)

Jan 06 13:44:41 server1.nwg.website systemd1: mmo.service: Service has Restart Warning: Journal has been rotated since unit was started. Log output is incomple lines 1-7/7 (END) * mmo.service - runs the mmo Loaded: error (Reason: Invalid argument) Active: failed (Result: signal) since Thu 2018-01-04 02:48:53 UTC; 2 days ago Main PID: 757 (code=killed, signal=KILL)

EDIT / progress : Now able to start the service ( more info in the long comments below), however when I try to add "Restart=on-failure" it gives the error where it complains that the service has a restart - I tried changing it to simple but that didn't help - what do I do?

  • I'd recommend to start the service as a seperate user instead of root. Apart from that you could use a simple bash-script to check if the process is running and then restart if necessary. You could start this script with bg in the background or use a cronjob to check every minute if its still there. – noreabu Jan 6 '18 at 12:52
0

Your steps were correct so far. I would recommend to set the permissions to 644 as the service file does not need to be executable.
You also have to run systemctl daemon-reload to pick up the new .service file. If you do changes to this file, you have to run this command to pick up the changes as well.

To make your service restart, you could add the Restart option in the [Service] section.

...
[Service]
...
Restart=on-failure
...

You also could add the option as follows, to control the interval between the restart attemps. Default seems to be 100ms.

RestartSec=

For further details refer to man systemd.service.

  • thank you Thomas for your quick reply! the issue is that the service doesn't appear when typing service --status-all, ( even after rebooting or systemctl daemon-reload ) - in the above screenshot, you can see the file looks different for some reason, not sure if it is because I'm using windows - I tried editing and uploading it on OSX but same thing – Yuriy Nikshych Jan 6 '18 at 13:51
  • You have to use systemctl [status|start|stop|reload...] to control and configure the service. service is obsolete with Ubuntu 16.04. – Thomas Jan 6 '18 at 13:59
  • Okay, I tried to run it but it says "invalid argument" : root@server1:~# systemctl start mmo.service Failed to start mmo.service: Unit mmo.service is not loaded properly: Invalid ar gument. server1.nwg.website systemd[1]: mmo.service: Service has Restart Warning: Journal has been rotated since unit was started. Log output is incomple lines 1-7/7 (END)...skipping... * mmo.service - runs the mmo Loaded: error (Reason: Invalid argument) Active: failed (Result: signal) since Thu 2018-01-04 02:48:53 UTC; 2 days ago – Yuriy Nikshych Jan 6 '18 at 14:05
  • ( I updated the .service and added the Restart=on-failure code - I updated the original post to reflect this) – Yuriy Nikshych Jan 6 '18 at 14:08
  • What is the output of systemctl status mmo and journalctl -u mmo? – Thomas Jan 6 '18 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.