12.3 - systemd - Forcing a script to run before rsyslog start

Hello.
I am trying to make a script starting before rsyslog start. I install all the stuff this way :
I use sasi ( https://forums.opensuse.org/blogs/jdmcdaniel3/s-s-i-suse-automated-script-installer-version-1-03-52/ ) from** jdmcdaniel **](https://forums.opensuse.org/members/jdmcdaniel3.html)to install my script.
For the moment, my script ( /etc/init.d/clock_generator ) do nothing but create a test variable.
I feed sasi with these to mandatory files:

#! /bin/sh
#
# Copyright (c) 2010 SuSE LINUX Products GmbH, Germany.  All rights reserved.
#
# Author: Werner Fink, 2010
#
#
# script with local commands to be executed from init before executing/root/bin/systemd_rm_clock_generator.service
# any script of a runlevel.
#
# Here you should add things, that should happen directly before entering
# a runlevel. Common environment variables for this are:
#  RUNLEVEL  -- The current system runlevel.
#  PREVLEVEL -- The previous runlevel (useful after a runlevel switch).
#
#
# Author: jcdole, 2013_06_30
#
# /etc/init.d/clock_generator
#

declare -i FOREVER=1 ON_DURATION=10 OFF_DURATION=10
#
export A_VAR_FLAG="ABCDEF"
#

And the service definition is :

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
# /lib/systemd/system/clock_generator.service
#

[Unit]
Description=/etc/init.d/clock_generator.service Compatibility
ConditionFileIsExecutable=/etc/init.d/clock_generator
Before=syslog.service

[Service]
Type=oneshot
ExecStart=/etc/init.d/clock_generator
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99

[Install]
WantedBy=multi-user.target

So based on recommendations I get from a previous post ( https://forums.opensuse.org/english/get-technical-help-here/install-boot-login/480807-script-running-during-halt-shutdown-but-before-disk-unmounted.html ) I add the following link to force rsyslog to start after my script:

mkdir -v  /etc/systemd/system/syslog.service.requires
ln -s   /etc/systemd/system/clock_generator.service   /etc/systemd/system/syslog.service.requires

I run into problem. The system cannot start the login service because my service clock_generator.service failed to start.
From systemd journal :

Jul 01 16:50:15 linux-hkl6.site systemd[1]: Failed to start Login Service.
Jul 01 16:50:15 linux-hkl6.site systemd[1]: Unit systemd-logind.service entered failed state
Jul 01 16:50:15 linux-hkl6.site systemd[1]: systemd-logind.service holdoff time over, scheduling restart.
Jul 01 16:50:15 linux-hkl6.site systemd[1]: Stopping Login Service...
Jul 01 16:50:15 linux-hkl6.site systemd[1]: Starting Login Service...
............
............
............
Jul 01 16:51:45 linux-hkl6.site systemd[1]: systemd-logind.service operation timed out. Terminating.
Jul 01 16:51:45 linux-hkl6.site systemd[1]: Failed to start Login Service.
Jul 01 16:51:45 linux-hkl6.site systemd[1]: Unit systemd-logind.service entered failed state
Jul 01 16:51:45 linux-hkl6.site systemd[1]: systemd-logind.service holdoff time over, scheduling restart.
Jul 01 16:51:45 linux-hkl6.site systemd[1]: Stopping Login Service...
Jul 01 16:51:46 linux-hkl6.site systemd[1]: Starting Login Service...
Jul 01 16:53:16 linux-hkl6.site systemd[1]: systemd-logind.service operation timed out. Terminating.
Jul 01 16:53:16 linux-hkl6.site systemd-journal[304]: Forwarding to syslog missed 14 messages.
Jul 01 16:53:16 linux-hkl6.site systemd[1]: Failed to start Login Service.
Jul 01 16:53:16 linux-hkl6.site systemd[1]: Unit systemd-logind.service entered failed state
Jul 01 16:53:16 linux-hkl6.site systemd[1]: systemd-logind.service holdoff time over, scheduling restart.
Jul 01 16:53:16 linux-hkl6.site systemd[1]: Stopping Login Service...
Jul 01 16:53:16 linux-hkl6.site systemd[1]: Starting Login Service...
............
............
............
Jul 01 16:53:45 linux-hkl6.site systemd[1]: Starting /etc/init.d/clock_generator.service Compatibility...
...........
Jul 01 16:53:46 linux-hkl6.site systemd[1]: clock_generator.service: main process exited, code=exited, status=127/n/a
Jul 01 16:53:46 linux-hkl6.site systemd-journal[304]: Forwarding to syslog missed 13 messages.
Jul 01 16:53:46 linux-hkl6.site systemd[1]: Failed to start /etc/init.d/clock_generator.service Compatibility.
Jul 01 16:53:46 linux-hkl6.site systemd[1]: Dependency failed for System Logging Service.
Jul 01 16:53:46 linux-hkl6.site systemd[1]: Job rsyslog.service/start failed with result 'dependency'.
Jul 01 16:53:46 linux-hkl6.site systemd[1]: Unit clock_generator.service entered failed state

But sometimes the system gets to start very late.
Here a full copy of systemd journal :
SUSE Paste

Why do you create a .service file to call the /etc/init.d script? That’s unnecessary, systemd can use the /etc/init.d scripts directly.
So either create a .service file OR use the init script I would say.

To your problem:
That link specifies that the syslog.target REQUIRES your clock_generator service. So if your script fails, the whole target fails.
If you use syslog.service.wants instead, it should work even if your script fails I guess.
But the “Before=syslog.target” in your .service file should be enough I think. (you have to enable your service with “systemctl enable clock_generator.service” of course if you don’t create the link manually, which you shouldn’t anyway)

Something like this is also possible with init scripts, see:
https://en.opensuse.org/openSUSE:Packaging_init_scripts#.23_X-Start-Before:_line
So in your case, add “# X-Start-Before: $syslog” to the header.
But since this is marked as openSUSE-specific I don’t know if systemd still respects this.

First, I do not claim to be an expert on old init scripts or the new systemd and love to get better information to learn how that systemd works. However, not all old init scripts work with systemd and further, there is nothing wrong with creating a service file to run a script if it does not work as intended. One such example of a init script driver application is dkms as supplied by Packman. Under systemd, it does not work as installed in openSUSE 12.2 or 12.3. This has been true since systemd became the norm in openSUSE. I do understand they have dkms working with Bumblebee and the nVIDIA driver, but I have not looked to see how they did it. To get dkms to work for me, I moved its startup script and created a service file for it. I am sure there are all sorts of solutions that work, but using a service file is not a bad option and it is more flexible in my opinion, the very reason why systemd was installed. Using dkms to reload the VirtualBox driver on kernel updates is very handy and I even have it working with the nVIDIA driver and no Bumblebee is being used.

Anyway, its just my opinion, and I would love to hear more on the subject.

Thank You,

Of course it’s possible that some init scripts don’t work with systemd, yes. That’s why I mentioned that “X-Start-Before” may not work with systemd…
Although I never encountered one that doesn’t work personally, even a self-written one by me worked flawlessly after upgrading to systemd, although I’m by no means an expert regarding that.:wink:

And I never used dkms, so don’t know specifics about that.
Regarding virtualbox and nvidia, I prefer to use the versions from the openSUSE repos, so no dkms necessary here (that doesn’t work of course if you upgrade to a newer kernel than the standard one…)

So I do not claim to understand what you are doing, but you could modify the rsyslog service file and add a line there perhaps as shown in bold:

[Unit]
Description=System Logging Service
Requires=var-run.mount syslog.target
After=var-run.mount
Before=syslog.target
Conflicts=syslog-ng.service syslogd.service

[Service]
Environment=RSYSLOGD_PARAMS=
**ExecStartPre=/usr/local/bin/userfix**
ExecStartPre=/usr/sbin/rsyslog-service-prepare
EnvironmentFile=-/etc/sysconfig/syslog
ExecStart=/usr/sbin/rsyslogd -n $RSYSLOGD_PARAMS
ExecReload=/bin/kill -HUP $MAINPID
Sockets=syslog.socket
StandardOutput=null

[Install]
WantedBy=multi-user.target
Alias=syslog.service

This would run a bash script called userfix before doing anything else. Restart your PC after the change and see what you get. You can use my SysdCmd bash script to find and edit the rsyslog service file.

SysdCmd - systemd Command Help/Config Editor - Blogs - openSUSE Forums

Thank You,

On 2013-07-03 11:26, jcdole wrote:
>
> Hello.
> I am trying to make a script starting before rsyslog start. I install
> all the stuff this way :

I have this service unit to do just that (the initial coding is from
arvidjaar):


cer@Telcontar:/etc/systemd/system> cat boot-marker.service
[Unit]
Description=Write boot markers in /var/log/messages
Before=syslog.service

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=-/usr/local/bin/write-boot-marker start
ExecStop=-/usr/local/bin/write-boot-marker stop

[Install]
WantedBy=multi-user.target

cer@Telcontar:/etc/systemd/system>

The “Before” clause ensures it runs before syslog, nothing else is
needed (just run “systemctl enable whatever.service”). Notice that the
script I run does not reside in /etc/init.d/


Cheers / Saludos,

Carlos E. R.
(from 12.3 x86_64 “Dartmouth” at Telcontar)

I will try this and give you news.

Thank you for helping.

I will try also this.

The "Before" clause ensures it runs before syslog, nothing else is
needed (just run "systemctl enable whatever.service"). Notice that the
script I run does not reside in /etc/init.d/

Noted.

Thank you for helping.