Re: [systemd-devel] Starting a service before any networking

2023-09-27 Thread Jan Hugo Prins
I think the main problem you are running into is the DefaultDependencies 
option. When this is set to on, several default dependencies are being 
enforced which make sure that at least a basic system is up and running 
before anything else is started. When you want to start something before 
the basic system is up and running and want, for example, just to be 
sure that all the filesystems are mounted, you can do something like this:


    [Unit]
    DefaultDependencies=no
    After=local-fs.service
    Before=dependent_service1.service dependent_service2.service
    Conflicts=shutdown.target initrd-switch-root.target
    [Service]
    Type=oneshot
    TimeoutStartSec=600
    RemainAfterExit=yes
    ExecStart=
    [Install]
    WantedBy=sysinit.target


Best regards,

Jan Hugo Prins


Op 26-09-2023 om 12:50 schreef Mark Rogers:

I'm sure this is trivial but I've gone round in circles without success.

I have a script which reads from an SQLite database and generates 
various system configuration files - at the moment these are 
dhcpcd.conf and wpa_supplicant.conf but this might grow in future.


As such the only dependency the script has is that the filesystem is 
up and running. But the script must complete before anything that the 
script manages the configuration file for.


My current unit looks like this:
[Unit]
Before=networking.service
After=local-fs.target

[Service]
Type=oneshot
ExectStart=/path/to/script

[Install]
RequiredBy=network.target

Where am I going wrong and what is the right way to do this?

I've also tried Before=network-pre.target and Wants=network-pre.target 
without success - it was that not working that set me off trying to 
fix it.

--
Mark Rogers


Re: [systemd-devel] Only start a tomcat server when you are sure that time-sync.target is online

2021-03-25 Thread Jan Hugo Prins
Hi,

> > Does systemd give me a different way to check if the time is in sync?
> > Is there a way to create this dependency without implying a restart when
> > ntpd restarts?
> https://unix.stackexchange.com/questions/388586/systemd-requires-vs-wants
> 
>
> just replace "Requires" with "Wants", it does exactly the same but your
> Tomcat would also get started if "time-sync.target" is missing *but* it
> would not be stopped just because ntpd is stopped
>
> there are really very few cases when Requires is really what someone wants

We first tried it with wants, but wants does start the application
server even if the time-sync.target does not work.

>From the man page:
   Units listed in this option will be started if the
configuring unit is. *However, if the listed units fail to start or
cannot be added to the**
**   transaction, this has no impact on the validity of the
transaction as a whole*, and this unit will still be started. This is
the recommended
   way to hook the start-up of one unit to the start-up of
another unit.

We don't want tomcat to start when time-sync doesn't succeed, but when
ntpd restarts it should not influence tomcat.

Jan Hugo

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


[systemd-devel] Only start a tomcat server when you are sure that time-sync.target is online

2021-03-25 Thread Jan Hugo Prins
Hello,

In our platform we have a dependency where we want to be sure that the
time-sync.target is online before we start our application servers. We
do this because we really want to be sure that the time on the
application server is in sync with our NTP servers. The downside of the
way we have done this at the moment is that making a configuration
change on ntp.conf results in a restart of ntpd, which in turn results
in a restart of the application servers. This is really not what we
want, because we actually want to be sure that the time is correct, and
a restart of the ntpd service on a server doesn't put the time on the
server at risk immediately.

Our current configuration looks roughly like this:

[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target time-sync.target
Requires=time-sync.target

[Service]
Type=simple
ExecStart=Startscripts
ExecStop=Stopscript
SuccessExitStatus=143
User=tomcatuser
Group=tomcatuser
Restart=on-failure

[Install]
WantedBy=multi-user.target


The problem line is the Requires line in there I think.

Does systemd give me a different way to check if the time is in sync?
Is there a way to create this dependency without implying a restart when
ntpd restarts?

Jan Hugo Prins


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