0

After doing an rpm install which also starts the service 'homemade-auth-svc', it seems to start up happily enough but then fails and continually restarts.

journalctl -ex u homemade-auth-svc.service:

Jan 14 21:01:51 UI systemd[1]: Starting A service for homemade authentication....                
-- Subject: Unit homemade-auth-svc.service has begun with start-up                               
-- Defined-By: systemd                                                                      
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel                     
--                                                                                          
-- Unit homemade-auth-svc.service has begun starting up.                                         
Jan 14 21:01:51 UI homemade-auth-svc[1709]: homemade-auth: starting...                                
Jan 14 21:01:51 UI systemd[1]: Started A service for homemade authentication..                   
-- Subject: Unit homemade-auth-svc.service has finished start-up                                 
-- Defined-By: systemd                                                                      
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel                     
--                                                                                          
-- Unit homemade-auth-svc.service has finished starting up.                                      
--                                                                                          
-- The start-up result is done.                                                             
Jan 14 21:01:51 UI systemd[1]: homemade-auth-svc.service holdoff time over, scheduling restart.  
Jan 14 21:01:51 UI systemd[1]: Stopping A service for homemade authentication....                
-- Subject: Unit homemade-auth-svc.service has begun shutting down                               
-- Defined-By: systemd                                                                      
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel                     
--                                                                                          
-- Unit homemade-auth-svc.service has begun shutting down.                                       
Jan 14 21:01:51 UI systemd[1]: Starting A service for homemade authentication....                
-- Subject: Unit homemade-auth-svc.service has begun with start-up                               
-- Defined-By: systemd                                                                      
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel                     
....                                                                                        

systemctl status homemade-auth-svc:

    homemade-auth-svc.service - A service for homemade authentication.
   Loaded: loaded (/usr/lib/systemd/system/homemade-auth-svc.service; enabled)                                   
   Active: failed (Result: start-limit) since Thu 2016-01-14 21:01:52 PST; 20min ago                        
  Process: 1725 ExecStart=/usr/bin/HomemadeAuthSvc (code=exited, status=0/SUCCESS)                               
 Main PID: 1725 (code=exited, status=0/SUCCESS)                                                             
   CGroup: /system.slice/homemade-auth-svc.service                                                               

Jan 14 21:01:52 UI systemd[1]: homemade-auth-svc.service holdoff time over, scheduling restart.                  
Jan 14 21:01:52 UI systemd[1]: Stopping A service for homemade authentication....                                
Jan 14 21:01:52 UI systemd[1]: Starting A service for homemade authentication....                                
Jan 14 21:01:52 UI systemd[1]: homemade-auth-svc.service start request repeated too quickly, refusing to start.  
Jan 14 21:01:52 UI systemd[1]: Failed to start A service for homemade authentication..                           
Jan 14 21:01:52 UI systemd[1]: Unit homemade-auth-svc.service entered failed state.                              

homemade-auth-svc.service:

[Unit]                                           
Description=A service for homemade authentication.    
After=network.target                             

[Service]                                        
Type=notify                                      
NotifyAccess=all                                 
ExecStart=/usr/bin/HomemadeAuthSvc                    
StandardOutput=null                              
Restart=always                                   

[Install]                                        
WantedBy=multi-user.target                       
Alias=homemade-auth-svc.service                       

We call sd_notify(0, "READY=1"); in the child, daemon process, but, it doesn't seem to matter if we instead do it in the parent after waiting 10 seconds then successfully exiting. systemd then just waits that long before giving the same result. It's as if it waits for sd_notify(), declares success and then immediately restarts the service. Now, the rpm modifies lightdm.service (a log-in service) to depend on us (installs a file with the contents:

[Unit]
Wants=homemade-auth-svc.service

into: /etc/systemd/system/lightdm.service.d/ )

but since lightdm is already running I don't imagine that should be a problem.

Systemd is version 208 running on Fedora 20.

  • Your program should not attempt to daemonize itself. That's the only obvious thing I see here. – Michael Hampton Jan 21 '16 at 2:44
  • @Michael Hampton it does a typical fork daemonization - parent forks daemon, then exits. I have done sd_notify from both the parent (just before the exit(EXIT_SUCCESS)), and alternately from the child. This all works when [Service]Type=forking and without sd_notify, we just want to express that we're READY only after we've fetched from a DB (we have the list of authorized accounts). If the DB fails that's fine - lightdm's dependency on this is only Wants=... and not Requires=..., we just want a best-effort. – Jeff Donner Jan 21 '16 at 18:15
  • Right, you need to fix the program so that it does not fork. – Michael Hampton Jan 21 '16 at 18:17
  • @MichaelHampton not fork? Is this because it uses Type=notify instead of Type=forking? Is it safe to have a service that isn't forked? Thanks regardless, the problem being forking when not Type=forking hadn't occurred to me. – Jeff Donner Jan 21 '16 at 19:11
  • That's what I said twice already! – Michael Hampton Jan 21 '16 at 19:12
0

Per Michael Hampton and some semi-confirmatory browsing of the systemd-devel mailing list, it looks like you can't use sd_notify (& Type=notify) with traditional fork()ed daemons. So, I made the service be good old Type=forking and had the child tell the parent via a shared pipe when the child was ready, upon which the parent exits, which in turn lets systemd know the service is READY.

FWIW, our attempt at stalling the dependent service (login manager) for a couple seconds failed, systemd waited < 1s before starting it.

|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.