Re: [systemd-devel] umount fails on system with huge (2TiB) buff/cache

2024-01-31 Thread Holger Kiehl
Hello,

On Tue, 30 Jan 2024, Michal Koutný wrote:

> Hello.
> 
> On Fri, Jan 26, 2024 at 12:13:34PM +0000, Holger Kiehl  
> wrote:
> ...
> > Note it states 'no limit' and one can see after some minutes it says
> > it umounted /mnt/u2:
> ...
> > Confused here since it stated on serial console output
> > 
> >[  OK  ] Unmounted /mnt/u2.
> 
> Any chance your mount unit has LazyUnmount=yes?
> 
I just checked, it is not set:

   systemctl show mnt-u2.mount|grep LazyUnmount
   LazyUnmount=no

> > The only way I can get the system to reboot properly is when sending the
> > following command before doing the reboot:
> > 
> >echo 1 > /proc/sys/vm/drop_caches
> 
> How long does this take BTW? (Around those 10 minutes?)
> 
Yes. And I have the feeling the longer the system is running the
longer it takes. I remember seeing values of 15 minutes.

> > Is it possible to tell systemd-shutdown to wait longer or are there
> > some other parameters I need to tune?
> 
> systemd-shutdown uses sum of values from
> /proc/meminfo:{NFS_Unstable,Writeback,Dirty} to determine whether the sync
> progresses. Something in block/FS layer may got stuck if it doesn't
> apparently decrease.
> 
These values seem low if I look now:

   grep -E 'NFS_Unstable|Writeback:|Dirty' /proc/meminfo
   Dirty:142600 kB
   Writeback:   204 kB
   NFS_Unstable:  0 kB

Just in case, here is what cat /proc/meminfo shows:

   MemTotal:   2100404416 kB
   MemFree: 6588452 kB
   MemAvailable:   2071304740 kB
   Buffers:16754436 kB
   Cached: 1987217352 kB
   SwapCached:   12 kB
   Active:  4265420 kB
   Inactive:   2000405976 kB
   Active(anon): 752288 kB
   Inactive(anon):  280 kB
   Active(file):3513132 kB
   Inactive(file): 2000405696 kB
   Unevictable:  176784 kB
   Mlocked:  176784 kB
   SwapTotal:  23238652 kB
   SwapFree:   23231484 kB
   Zswap: 0 kB
   Zswapped:  0 kB
   Dirty:   1127136 kB
   Writeback:56 kB
   AnonPages:876600 kB
   Mapped:   196720 kB
   Shmem: 36580 kB
   KReclaimable:   70815728 kB
   Slab:   80465432 kB
   SReclaimable:   70815728 kB
   SUnreclaim:  9649704 kB
   KernelStack:   48720 kB
   PageTables:13416 kB
   SecPageTables: 0 kB
   NFS_Unstable:  0 kB
   Bounce:0 kB
   WritebackTmp:  0 kB
   CommitLimit:1073440860 kB
   Committed_AS:2024660 kB
   VmallocTotal:   34359738367 kB
   VmallocUsed:  522548 kB
   VmallocChunk:  0 kB
   Percpu:   708608 kB
   HardwareCorrupted: 0 kB
   AnonHugePages: 0 kB
   ShmemHugePages:0 kB
   ShmemPmdMapped:0 kB
   FileHugePages: 0 kB
   FilePmdMapped: 0 kB
   CmaTotal:  0 kB
   CmaFree:   0 kB
   Unaccepted:0 kB
   HugePages_Total:   0
   HugePages_Free:0
   HugePages_Rsvd:0
   HugePages_Surp:0
   Hugepagesize:   2048 kB
   Hugetlb:   0 kB
   DirectMap4k:  246592 kB
   DirectMap2M:16109568 kB
   DirectMap1G:2118123520 kB

Regards,
Holger

[systemd-devel] umount fails on system with huge (2TiB) buff/cache

2024-01-26 Thread Holger Kiehl
Hello,

with huge memory buff/cache a umount can take very long:

   time umount /mnt/u2

   real 10m43.026s
   user 0m0.000s
   sys  10m27.985s

which then causes a system not to umount the device properly when
rebooting, watching serial console:

   [  OK  ] Deactivated swap /dev/sda4.
   [  OK  ] Unmounted /boot.
   [  OK  ] Deactivated swap /dev/disk…0-c79c-4437-922e-21bb8c926cf8.
   [  OK  ] Stopped File System Check …9-80c6-4dc9-86db-f3a9ec179b3c.
   [244820.237512] audit: type=1131 audit(1706268318.490:23423): pid=1 uid=0 
auid=4294967295 ses=4294967295 
msg='unit=systemd-fsck@dev-disk-by\x2duuid-d079cce9\x2d80c6\x2d4dc9\x2d86db\x2df3a9ec179b3c
 comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? 
res=success'
   [  OK  ] Stopped File System Check on /dev/mapper/datao1db.
   [244820.273498] audit: type=1131 audit(1706268318.526:23424): pid=1 uid=0 
auid=4294967295 ses=4294967295 msg='unit=systemd-fsck@dev-mapper-datao1db 
comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? 
res=success'
   [  OK  ] Unmounted /mnt/hdd1.
   [  OK  ] Stopped File System Check on /dev/mapper/datao1da.
   [244820.409479] audit: type=1131 audit(1706268318.662:23425): pid=1 uid=0 
auid=4294967295 ses=4294967295 msg='unit=systemd-fsck@dev-mapper-datao1da 
comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? 
res=success'
   [   ***] A stop job is running for /mnt/u2 (2min 55s / no limit)

Note it states 'no limit' and one can see after some minutes it says
it umounted /mnt/u2:

   [  OK  ] Unmounted /mnt/u2.
   [  OK  ] Reached target Unmount All Filesystems.
   [  OK  ] Stopped File System Check …f-5fca-4f3b-b51d-9bd61b3afed2.
   [245090.42] audit: type=1131 audit(1706268588.681:23426): pid=1 uid=0 
auid=4294967295 ses=4294967295 
msg='unit=systemd-fsck@dev-disk-by\x2duuid-37da47ff\x2d5fca\x2d4f3b\x2db51d\x2d9bd61b3afed2
 comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? 
res=success'
   [  OK  ] Removed slice Slice /system/systemd-fsck.
   [  OK  ] Stopped target Preparation for Local File Systems.
Stopping Device-Mapper Multipath Device Controller...
   [  OK  ] Stopped Remount Root and Kernel File Systems.
   [245090.487727] audit: type=1131 audit(1706268588.741:23427): pid=1 uid=0 
auid=4294967295 ses=4294967295 msg='unit=systemd-remount-fs comm="systemd" 
exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
   [  OK  ] Stopped File System Check on Root Device.
   [245090.516713] audit: type=1131 audit(1706268588.770:23428): pid=1 uid=0 
auid=4294967295 ses=4294967295 msg='unit=systemd-fsck-root comm="systemd" 
exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
   [  OK  ] Stopped Create Static Device Nodes in /dev.
   [245090.544717] audit: type=1131 audit(1706268588.798:23429): pid=1 uid=0 
auid=4294967295 ses=4294967295 msg='unit=systemd-tmpfiles-setup-dev 
comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? 
res=success'
   [  OK  ] Stopped Device-Mapper Multipath Device Controller.
   [245090.575750] audit: type=1131 audit(1706268588.829:23430): pid=1 uid=0 
auid=4294967295 ses=4294967295 msg='unit=multipathd comm="systemd" 
exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
   [  OK  ] Reached target System Shutdown.
   [  OK  ] Reached target Late Shutdown Services.
   [  OK  ] Finished System Reboot.
   [245090.619726] audit: type=1130 audit(1706268588.873:23431): pid=1 uid=0 
auid=4294967295 ses=4294967295 msg='unit=systemd-reboot comm="systemd" 
exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
   [245090.639307] audit: type=1131 audit(1706268588.873:23432): pid=1 uid=0 
auid=4294967295 ses=4294967295 msg='unit=systemd-reboot comm="systemd" 
exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
   [  OK  ] Reached target System Reboot.
   [245090.672034] audit: type=1334 audit(1706268588.925:23433): prog-id=60 
op=UNLOAD
   [245090.679574] audit: type=1334 audit(1706268588.925:23434): prog-id=59 
op=UNLOAD
   [245090.687105] audit: type=1334 audit(1706268588.927:23435): prog-id=63 
op=UNLOAD
   [245120.718949] systemd-shutdown[1]: Syncing filesystems and block devices - 
timed out, issuing SIGKILL to PID 3377584.
   [245120.730995] systemd-journald[2863]: Failed to send WATCHDOG=1 
notification message: Connection refused
   [245120.774387] systemd-journald[2863]: Received SIGTERM from PID 1 
(systemd-shutdow).
   [245130.775151] systemd-shutdown[1]: Waiting for process: 3377515 (umount), 
3377584 ((sd-sync))
   [245210.836634] systemd-shutdown[1]: Sending SIGKILL to PID 3377515 (umount).
   [245210.857197] systemd-shutdown[1]: Sending SIGKILL to PID 3377584 
((sd-sync)).
   [245220.880927] systemd-shutdown[1]: Waiting for process: 3377515 (umount), 
3377584 ((sd-sync))
   [245280.135213] INFO: task (sd-sync):3377584 blocked for more than 122 
seconds.
   [245280.155688] 

Re: [systemd-devel] more verbose debug info than systemd.log_level=debug?

2017-04-09 Thread Holger Kiehl
On Sat, 8 Apr 2017, Chris Murphy wrote:

> On Tue, Apr 4, 2017 at 11:55 AM, Andrei Borzenkov  wrote:
> > grub2 is not limited to 640KiB. Actually it will actively avoid using
> > low memory. It switches to protected mode as the very first thing and
> > can use up to 4GiB (and even this probably can be lifted on 64 bit
> > platform). The real problem is the fact that grub is read-only so every
> > time you access file on journaled partition it will need to replay
> > journal again from scratch. This will likely be painfully slow (I
> > remember that grub legacy on reiser needed couple of minutes to read
> > kernel and much more to read initrd, and that was when both were smaller
> > than now).
> 
> OK well that makes more sense; but yeah it still sounds like journal
> replay is a non-starter. The entire fs metadata would have to be read
> into memory and create something like a RAM based rw snapshot which is
> backed by the ro disk version as origin, and then play the log against
> the RAM snapshot. That could be faster than constantly replaying the
> journal from scratch for each file access. But still - sounds overly
> complicated.
> 
> I think this qualifies as "Doctor, it hurt when I do this." And the
> doctor says, "So don't do that." And I'm referring to Plymouth
> exempting itself from kill while also not running from initramfs. So
> I'll kindly make the case with Plymouth folks to stop pressing this
> particular hurt me button.
> 
> But hey, pretty cool bug. Not often is it the case you find such an
> old bug so easily reproducible but near as I can tell only one person
> was hitting it until I tried to reproduce it.
> 
I too was hit by this bug on one of my systems. But what I did is that
I just removed all plymouth rpms and everything was good form that moment
on.

Holger
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Started process not attach to its related service.

2016-11-22 Thread Holger Kiehl
On Tue, 22 Nov 2016, Mantas Mikulėnas wrote:

> So, uh, that sounded like you value updating one file less (and even mixing
> user and daemon configs) above having the service actually work?
>
But users do test things under their login environment and expect them
to run in this environment. So for some applications this is a must.

> Not that it's an excuse anyway. Systemd units have EnvironmentFile= for
> importing environment variables. Even init.d scripts can use `source` with
> the same effect, as can users' own .profile or .foorc scripts... There are
> plenty of nice ways to "share environment variables" without using su.
> 
Users have different shell's and even distributions name them differently
(.profile, .bash_profile). With EnvironmentFile= you force the user to put
the same things at two different places. With su you do not have to
think about all these problems.

Regards,
Holger

> That said, at least try `runuser`...
> 
> On Tue, Nov 22, 2016, 12:07 Benoit SCHMID  wrote:
>   Hello,
> 
>   On 11/22/2016 10:58 AM, Jonathan de Boyne Pollard wrote:
>   > Don't abuse su for dropping privileges.
> 
>   I agree that using su has drawbacks.
> 
>   But it also have advantages.
>   When you upgrade your db, you upgrade the environment variables.
>   Therefore using su allow you to centralised everything in one
>   place
>   (user settings).
> 
>   This is why, after thinking of the pros and cons, I use su,
>   even if I agree with you, on the fact that should not abuse :-)
> 
>   Regards,
> 
>   --
>   _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
> 
>        Benoit Schmid              Tel: (+41-22) 379-7209
> 
>        University of Geneva - Information Technology Division
> 
>   _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
> 
>   ___
>   systemd-devel mailing list
>   systemd-devel@lists.freedesktop.org
>   https://lists.freedesktop.org/mailman/listinfo/systemd-devel
> 
> 
> ___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


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

2016-07-18 Thread Holger Kiehl
On Fri, 15 Jul 2016, Mantas Mikulėnas wrote:

> On Thu, Jul 14, 2016 at 3:34 PM, Holger Kiehl  wrote:
>   Hello,
> 
>   I am new to systemd and the maintainer of the file distribution
>   software
>   AFD (http://www.dwd.de/AFD) and I am trying to adapt this
>   application
>   to systemd. The problem I am unable to solve is that doing a
>   reboot,
>   poweroff or halt, all process get a SIGTERM before systemd calls
>   the
>   command supplied by ExecStop. If I do a 'systemctl stop
>   afd.service'
>   everything works as expected. I have searched the web for a
>   solution
>   and have tried all the different service Type=, unit
>   After=/Before=
>   combination, but failed so far. I must be doing something
>   obviously
>   wrong, but unable to see what and need help please.
> 
>   The service/unit file looks as follows:
> 
>      [Unit]
>      Description=Automatic File Distributor
>      After=basic.target
> 
>      [Service]
>      RemainAfterExit=yes
>      Type=oneshot
>      ExecStart=-/etc/init.d/afd start
>      ExecStop=-/etc/init.d/afd stop
>      KillMode=none
>      StandardOutput=syslog+console
>      StandardError=syslog+console
> 
>      [Install]
>      WantedBy=multi-user.target
> 
>   /etc/init.d/afd is a shell script that starts one or more
>   instances of
>   the AFD under different users. The users are configured in
>   /etc/sysconfig/afd
>   and are started via the following command: su - $afduser -c
>   ""
>   To speed things up a bit the script forks for each user to
>   start/stop the
>   AFD instances. The script /etc/init.d/afd is just initiating
>   thinks, but
>   always waits for the command to complete. AFD itself has an init
>   process
>   (init_afd) that then starts several other process and monitors
>   them.
> 
> 
> It's possible that `su` moves its children to a different cgroup, making
> them no longer technically part of the service, but rather part of a user
> session.
> 
> Check whether `systemctl status afd` actually shows your sub-daemons while
> they're running... (Other useful tools are `systemd-cgls` or `ps axfo
> pid,user,unit,cmd`.) If that's the problem, try using `runuser -u $afduser
> …` instead.
> 
You are right. See my other mail I just send. systemd-cgls shows that it
is part of the user session. I did try running it with runuser, but that
does not work because AFD needs the user environment, that whats in
~/.profile (or .bash_profile, .cshrc, .login, etc).

> Better yet, forget init.d and create a native afd@.service, with one
> instance per user (afd@user1, afd@user2, etc.), each instance running
> *exactly one* daemon.
> 
But I have users that run multiple AFD's under one user, each in their on
working directory. Can this be done, without having to manually write a
unit file for each AFD instance?

Regards,
Holger___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


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

2016-07-18 Thread Holger Kiehl
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=? 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___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


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

2016-07-15 Thread Holger Kiehl


On Thu, 14 Jul 2016, Andrei Borzenkov wrote:

> 14.07.2016 15:34, Holger Kiehl пишет:
> > Hello,
> > 
> > I am new to systemd and the maintainer of the file distribution software
> > AFD (http://www.dwd.de/AFD) and I am trying to adapt this application
> > to systemd. The problem I am unable to solve is that doing a reboot,
> > poweroff or halt, all process get a SIGTERM before systemd calls the
> > command supplied by ExecStop. If I do a 'systemctl stop afd.service'
> > everything works as expected. I have searched the web for a solution
> > and have tried all the different service Type=, unit After=/Before=
> > combination, but failed so far. I must be doing something obviously
> > wrong, but unable to see what and need help please.
> > 
> > The service/unit file looks as follows:
> > 
> >[Unit]
> >Description=Automatic File Distributor
> >After=basic.target
> > 
> 
> This is redundant - it is default for any standard service
> 
> >[Service]
> >RemainAfterExit=yes
> >Type=oneshot
> 
> That's wrong (although it is unrelated to the problem you have). It
> means systemd expects ExecStart to run and finish. In your case it
> appears to work because you use RemainAfterExit, but if you look more
> closely, your service is in state where PID is exited.
> 
> >ExecStart=-/etc/init.d/afd start
> >ExecStop=-/etc/init.d/afd stop
> >KillMode=none
> 
> Well, in this case you rely on your service to behave well. You must be
> very confident :)
> 
> >StandardOutput=syslog+console
> >StandardError=syslog+console
> > 
> >[Install]
> >WantedBy=multi-user.target
> > 
> > /etc/init.d/afd is a shell script that starts one or more instances of
> 
> If you start multiple instances, you should consider service template so
> each instance can be represented as exactly one systemd service.
> 
> > the AFD under different users. The users are configured in 
> > /etc/sysconfig/afd
> > and are started via the following command: su - $afduser -c " > AFD>"
> 
> so what most likely happens, is - su establishes new login session; on
> shutdown these sessions are cleaned up (concurrently with any running
> service - unfortunately, there is no way to express dependency between
> user and system systemd instances). Here is where you get your signals.
> 
> Check with loginctl after service is started - do you see and extra seesion?
> 
> > To speed things up a bit the script forks for each user to start/stop the
> > AFD instances. The script /etc/init.d/afd is just initiating thinks, but
> > always waits for the command to complete. AFD itself has an init process
> > (init_afd) that then starts several other process and monitors them.
> > 
> > In /etc/init.d/afd I have added the following line in the beginning, before
> > it wants to do the shutdown:
> > 
> >echo "Before: ps -u afd: `ps -u $afduser`" >> /var/log/afd.log
> > 
> > And this then shows the following:
> > 
> >Before: ps -u afd:   PID TTY  TIME CMD
> > 1258 ?00:00:00 init_afd
> > 1260 ?00:00:00 system_log 
> > 1261 ?00:00:00 event_log 
> > 1262 ?00:00:00 receive_log 
> > 1263 ?00:00:00 transfer_log 
> > 1264 ?00:00:00 trans_db_log 
> > 1265 ?00:00:00 archive_watch 
> > 1266 ?00:00:00 input_log 
> > 1267 ?00:00:00 output_log 
> > 1268 ?00:00:00 delete_log 
> > 1269 ?00:00:00 production_log 
> > 1270 ?00:00:00 distribution_lo 
> > 1271 ?00:00:00 amg 
> > 1272 ?00:00:00 aldad 
> > 1287 ?00:00:00 afd_stat 
> > 1288 ?00:00:00 fd 
> > 1289 ?00:00:00 dir_check 
> > 
> > All the process have received a SIGTERM before (or during the execution)
> > of the script.
> > 
> > Any idea what I am doing wrong,
> 
> Much :)
> 
> > or what else I can try to do a proper
> > shutdown of this application under systemd?
> >
> 
> Use native systemd unit, do not use init scripts. Use User= to
> impersonate user, use Type=forking and PIDFile= to proper synchronize
> service startup, use templates to run multiple instances.
> 
First thank you very much for your very clear and good explaination.

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=? But if
I understand you correctly this too would not help because of the 'su -'.
Correct?

Regards,
Holger___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel


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

2016-07-14 Thread Holger Kiehl
Hello,

I am new to systemd and the maintainer of the file distribution software
AFD (http://www.dwd.de/AFD) and I am trying to adapt this application
to systemd. The problem I am unable to solve is that doing a reboot,
poweroff or halt, all process get a SIGTERM before systemd calls the
command supplied by ExecStop. If I do a 'systemctl stop afd.service'
everything works as expected. I have searched the web for a solution
and have tried all the different service Type=, unit After=/Before=
combination, but failed so far. I must be doing something obviously
wrong, but unable to see what and need help please.

The service/unit file looks as follows:

   [Unit]
   Description=Automatic File Distributor
   After=basic.target

   [Service]
   RemainAfterExit=yes
   Type=oneshot
   ExecStart=-/etc/init.d/afd start
   ExecStop=-/etc/init.d/afd stop
   KillMode=none
   StandardOutput=syslog+console
   StandardError=syslog+console

   [Install]
   WantedBy=multi-user.target

/etc/init.d/afd is a shell script that starts one or more instances of
the AFD under different users. The users are configured in /etc/sysconfig/afd
and are started via the following command: su - $afduser -c ""
To speed things up a bit the script forks for each user to start/stop the
AFD instances. The script /etc/init.d/afd is just initiating thinks, but
always waits for the command to complete. AFD itself has an init process
(init_afd) that then starts several other process and monitors them.

In /etc/init.d/afd I have added the following line in the beginning, before
it wants to do the shutdown:

   echo "Before: ps -u afd: `ps -u $afduser`" >> /var/log/afd.log

And this then shows the following:

   Before: ps -u afd:   PID TTY  TIME CMD
1258 ?00:00:00 init_afd
1260 ?00:00:00 system_log 
1261 ?00:00:00 event_log 
1262 ?00:00:00 receive_log 
1263 ?00:00:00 transfer_log 
1264 ?00:00:00 trans_db_log 
1265 ?00:00:00 archive_watch 
1266 ?00:00:00 input_log 
1267 ?00:00:00 output_log 
1268 ?00:00:00 delete_log 
1269 ?00:00:00 production_log 
1270 ?00:00:00 distribution_lo 
1271 ?00:00:00 amg 
1272 ?00:00:00 aldad 
1287 ?00:00:00 afd_stat 
1288 ?00:00:00 fd 
1289 ?00:00:00 dir_check 

All the process have received a SIGTERM before (or during the execution)
of the script.

Any idea what I am doing wrong, or what else I can try to do a proper
shutdown of this application under systemd?

Thanks in advance,
Holger
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel