I want to migrate gammu-smsd service to mariadb, so I have edited service systemctl edit --full gammu-smsd.service
– I have added mariadb.service
on After line.
[Unit]
Description=SMS daemon for Gammu
Documentation=man:gammu-smsd(1)
After=mariadb.service postgresql.service network-online.target
Checked that mariadb exists: systemctl list-units --type=service
:
mariadb.service loaded active running MariaDB 10.3.15 database server
But I do not see new dependency anywhere:
systemctl list-dependencies gammu-smsd.service
gammu-smsd.service
● ├─system.slice
● └─sysinit.target
● ├─dev-hugepages.mount
● ├─dev-mqueue.mount
● ├─fake-hwclock.service
● ├─keyboard-setup.service
● ├─kmod-static-nodes.service
● ├─proc-sys-fs-binfmt_misc.automount
● ├─resolvconf.service
● ├─sys-fs-fuse-connections.mount
● ├─sys-kernel-config.mount
● ├─sys-kernel-debug.mount
● ├─systemd-ask-password-console.path
● ├─systemd-binfmt.service
● ├─systemd-hwdb-update.service
● ├─systemd-journal-flush.service
● ├─systemd-journald.service
● ├─systemd-machine-id-commit.service
● ├─systemd-modules-load.service
● ├─systemd-random-seed.service
● ├─systemd-sysctl.service
● ├─systemd-sysusers.service
● ├─systemd-tmpfiles-setup-dev.service
● ├─systemd-tmpfiles-setup.service
● ├─systemd-udev-trigger.service
● ├─systemd-udevd.service
● ├─systemd-update-utmp.service
● ├─cryptsetup.target
● ├─local-fs.target
● │ ├─-.mount
● │ ├─boot.mount
● │ ├─DietPi.mount
● │ ├─systemd-fsck-root.service
● │ ├─systemd-remount-fs.service
● │ ├─tmp.mount
● │ └─var-log.mount
● └─swap.target
● └─var-swap.swap
Also, gammu-smsd starts before maria DB is ready.
Can anybody point what I am doing wrong? Thanks!
Best Answer
After=
only ensures that the service starts after the other service, if both services are activated.If you want to have a real dependency to mariadb you have to use
Requires=
orWants=
. This defines the following behavior:Usually you will still want to use
After=
, becauseRequire=
andWants=
don't ensure order. If you only useRequires=
orWants=
gammu-smsd may be started in parallel or before mariadb.If you use
Require=
andAfter=
gammu-smsd won't get started if mariadb fails to start. Where asWants=
still will get gammu-smsd started, if mariadb fails to start. The author of the gammu-smsd RPM probably put the After for both mariadb and postgresql there, so that you can choose between one, both or none of them by activating the appropriate services.In practice you don't necessarily need to add the
Requires=
orWants=
line to the gammu-smsd configuration. Just make sure that mariadb is activated.Your problem is probably, that mariadb successfully entered the running state but still isn't ready to accept connections. At least on RHEL mariadb is configured as
Type=simple
that means it immediately enters the running state as soon as the mariadb process is started, even though it isn't accepting connections yet.One simple and hacky way to deal with that would be to simply add a short delay to the start of gammu-smsd with:
A more advanced way would be to use something like this: https://github.com/vishnubob/wait-for-it.
For more information you should read the man pages for systemd.unit and systemd.service.