1

I'm working with Ubuntu Server 16.04.

Here's the .service file:

[Unit]
Description=NoDescpt

[Service]
ExecStart=/home/git/cmd/daphnei
Restart=always
KillSignal=SIGQUIT
Type=notify
NotifyAccess=all

[Install]
WantedBy=multi-user.target

And the related script /home/git/cmd/daphnei:

#!/bin/bash
cd /home/git/hsfzmun/server
/home/git/virtualenvs/hsfzmun/bin/daphne -b 0.0.0.0 -p 8001 -v2 config.asgi:channel_layer

What confused me is that the service will restart every 90 seconds, but I can't find out why.


I've found that the service's status is always activating, which means systemd doesn't know that the service has been started. However the script did start because I can visit my website. So what's wrong with it?

3
  • 2
    Check logs files – Federico Sierra Feb 24 '17 at 15:33
  • 1
    @FedericoSierra Logs are fine, no errors. Actually I have several services with the same issues. Does 90 seconds a special value for systemd? – hsfzxjy Feb 24 '17 at 15:44
  • Check the right log files with the right verbosity settings. – Wesley Feb 24 '17 at 16:01
3

You are using

Type=Notify

in your unit file. It means that the application should notify systemd when it is ready to server via sd-notify Systemd probably receives no notification from your app and restarts it.

Unless your application is sending notification to systemd, you should update corresponding line to

Type=simple 

Other option is to check whether daphne can send notification to systemd and turn the notification on.

Check systemd documentation on notify for more details on Type=notify

0
5

Since it hasn't stated that it is ready within 90 seconds (the default start timeout), systemd has decided that your service has failed. Failed services get everything killed off.

Becuase of Restart=always, your failed service is then restarted, and the cycle repeats.

Also, Restart=on-failure might be better in this case.

4
  • Thanks! But I still have a question: why systemd doesn't think my service has started even if my script worked well and didn't make any errors? – hsfzxjy Feb 24 '17 at 16:02
  • I am not sure about my knowledge in scripts but adding this might help User=root and Type="" Also, adding WorkingDirectory=/home/root will set script to directory. – Net Runner Feb 24 '17 at 16:08
  • @hsfzxjy Why would you have Restart=always in the first place if your script isn't supposed to run continuely? – Anubioz Feb 24 '17 at 16:14
  • @Anubioz actually the script starts a server but it was shutdowned and restarted cyclely. Now I've know the reason. – hsfzxjy Feb 24 '17 at 16:54

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.