0

I have installed my own service in :

/etc/systemd/system/MyService.service

with the following setup :

[Unit]
Description=This is My Awesome service
After=network.target

[Service]
Type=forking
ExecStart=/home/me/myProgram
Restart=always

[Install]
WantedBy=multi-user.target

I've also made it start on boot :

sudo systemctl enable MyService.service

But for some reason, the service restart really often, like every 2 minute

What did I do wrong ? How can I fix it so that it only restart when the service has been genuinely closed ?

EDIT :

I can see it restart for no reason :

me@myUbuntu:~ $ systemctl status MyService.service
● MyService.service - This is My Awesome service
   Loaded: loaded (/etc/systemd/system/MyService.service; enabled)
   Active: activating (start) since Wed 2016-08-17 08:30:27 UTC; 1min 28s ago
  Control: 2550 (MyService)
   CGroup: /system.slice/MyService.service
          └─2550 /home/me/myProgram
me@myUbuntu:~ $ systemctl status MyService.service
● MyService.service - This is My Awesome service
   Loaded: loaded (/etc/systemd/system/MyService.service; enabled)
   Active: activating (start) since Wed 2016-08-17 08:31:57 UTC; 13ms ago
  Control: 2575 (MyService)
   CGroup: /system.slice/MyService.service
           └─2575 /home/me/myProgram
1

If your Program exist the Parameter "Restart=always" will restart the Program. See here: https://wiki.archlinux.org/index.php/systemd for more details. Also important:

type=forking: systemd considers the service started up once the process forks and the parent has exited. For classic daemons use this type unless you know that it is not necessary. You should specify PIDFile= as well so systemd can keep track of the main process.

So if systemd need to track the process you need to create a pid-file.

|improve this answer|||||

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.