[systemd-devel] Problems trying to convert a System-V-Init script to systemd

Holger Kiehl Holger.Kiehl at dwd.de
Mon Jul 18 13:30:03 UTC 2016


On Fri, 15 Jul 2016, Andrei Borzenkov wrote:

> 15.07.2016 13:28, Holger Kiehl пишет:
> > I tried to avoid Type=forking and PIDFile= because I then have to maintain
> > two different init versions, systemd and System-V-Init. I think there will
> > always be other Unix systems around without systemd and I do not want to
> > loose those users.
> > 
> > Would it help if I build into my script for each instant it starts
> > it calls systemd-notify with --pid=<init_afd pid of the user>? But if
> 
> systemd expects there is one PID that represents the service (Main PID).
> If you have multiple equal instances, which one represents the service
> then? Do not forget that if main PID terminates, systemd assumes service
> has finished and cleans up. Of course you can cheat by preventing
> killing remaining processes but then you also lose service babysitting
> systemdm offers you.
> 
> > I understand you correctly this too would not help because of the 'su -'.
> > Correct?
> > 
> 
> That is what I expect based on your description. Did you check for extra
> logind sessions as I suggested?
> 

Running systemd-cgls it shows the following:

   ├─1 /usr/lib/systemd/systemd --switched-root --system --deserialize 21
   ├─user.slice
   │ └─user-1000.slice
   │   └─session-c2.scope
   │     ├─1291 init_afd -w /home/afd
   │     ├─1297 system_log -w /home/afd
   │     ├─1298 event_log -w /home/afd
   │     ├─1299 receive_log -w /home/afd
   │     ├─1300 transfer_log -w /home/afd
   │     ├─1301 trans_db_log -w /home/afd
   │     ├─1302 archive_watch -w /home/afd
   │     ├─1303 input_log -w /home/afd
   │     ├─1304 output_log -w /home/afd
   │     ├─1305 delete_log -w /home/afd
   │     ├─1306 production_log -w /home/afd
   │     ├─1307 distribution_log -w /home/afd
   │     ├─1308 amg -w /home/afd
   │     ├─1309 aldad -w /home/afd
   │     ├─1317 afd_stat -w /home/afd
   │     ├─1318 fd -w /home/afd
   │     └─1319 dir_check /home/afd 5 20 1 509
   └─system.slice
     ├─udisks2.service
     │ └─2552 /usr/lib/udisks2/udisksd --no-debug
     .
     .
     .
     .
     .

     ├─systemd-udevd.service
     │ └─387 /usr/lib/systemd/systemd-udevd
     ├─lvm2-lvmetad.service
     │ └─374 /usr/sbin/lvmetad -f
     └─systemd-journald.service
       └─361 /usr/lib/systemd/systemd-journald

So it runs in the user.slice as you expected. Here is what 'systemctl status
afd.service' has to say:

   ● afd.service - Automatic File Distributor
      Loaded: loaded (/usr/lib/systemd/system/afd.service; enabled; vendor preset: disabled)
      Active: active (exited) since Wed 2016-07-13 13:46:23 GMT; 4 days ago
 Main PID: 497 (code=exited, status=0/SUCCESS)
      CGroup: /system.slice/afd.service

   Jul 13 13:46:16 sl7x.dwd.de systemd[1]: Starting Automatic File Distributor...
   Jul 13 13:46:16 sl7x.dwd.de su[545]: (to afd) root on none
   Jul 13 13:46:23 sl7x.dwd.de su[1211]: (to afd) root on none
   Jul 13 13:46:23 sl7x.dwd.de afd[497]: Starting AFD for afd : Done
   Jul 13 13:46:23 sl7x.dwd.de systemd[1]: Started Automatic File Distributor.

I am beginning to wonder, even if I write proper unit files (using templates),
the user is allowed to start and stop his AFD, either via command line or GUI.
If he now does it with the provided tools, the process will again end up in
the user.slice. Unless he uses systemctl, ie. I have to rewrite the command
line for starting+stopping to use systemctl, so the user does not have to
change anything.

Is there no way one can tell systemd to just run a command at start and
when it stops, waiting for the command to complete? I do not need any
of those 'babysitting' services of systemd. In fact I don't want them.
init_afd takes care of this.

Regards,
Holger


More information about the systemd-devel mailing list