Results 1 to 8 of 8

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

  1. #1
    Join Date
    Jun 2008
    Location
    South-West France
    Posts
    489

    Default 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/jd...rsion-1-03-52/ ) from jdmcdaniel 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:
    Code:
    #! /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 :
    Code:
    #  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/...unmounted.html ) I add the following link to force rsyslog to start after my script:
    Code:
    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 :
    Code:
    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
    Thank you for helping. JCD
    _______________
    SAMBA-LDAP PDC server 13.1--ASUS R900V win8 + 13.1 KDE -- HP DV9350 desktop 12.3 KDE -- acer aspire 7736g win 7 pro - scan EPSON V500 - Brthr HL2150N - Samsung CLP-325W

  2. #2

    Default Re: 12.3 - systemd - Forcing a script to run before rsyslog start

    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:Pac...t-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.

  3. #3
    Join Date
    Mar 2010
    Location
    Austin - Texas
    Posts
    10,500
    Blog Entries
    48

    Smile Re: 12.3 - systemd - Forcing a script to run before rsyslog start

    Quote Originally Posted by wolfi323 View Post
    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:Pac...t-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,
    My Blog: https://forums.opensuse.org/blogs/jdmcdaniel3/

    Software efficiency halves every 18 months, thus compensating for Moore's Law

    Its James again from Austin, Texas

  4. #4

    Default Re: 12.3 - systemd - Forcing a script to run before rsyslog start

    Quote Originally Posted by jdmcdaniel3 View Post
    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.
    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.

    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...)

  5. #5
    Join Date
    Mar 2010
    Location
    Austin - Texas
    Posts
    10,500
    Blog Entries
    48

    Smile Re: 12.3 - systemd - Forcing a script to run before rsyslog start

    Quote Originally Posted by jcdole View Post
    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/jd...rsion-1-03-52/ ) from jdmcdaniel 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:
    Code:
    #! /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 :
    Code:
    #  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/...unmounted.html ) I add the following link to force rsyslog to start after my script:
    Code:
    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 :
    Code:
    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
    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:

    Code:
    [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,
    My Blog: https://forums.opensuse.org/blogs/jdmcdaniel3/

    Software efficiency halves every 18 months, thus compensating for Moore's Law

    Its James again from Austin, Texas

  6. #6
    Join Date
    Feb 2009
    Location
    Spain
    Posts
    22,438

    Default Re: 12.3 - systemd - Forcing a script to run before rsyslog start

    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):

    Code:
    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)

  7. #7
    Join Date
    Jun 2008
    Location
    South-West France
    Posts
    489

    Default Re: 12.3 - systemd - Forcing a script to run before rsyslog start

    Quote Originally Posted by jdmcdaniel3 View Post
    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:

    Code:
    [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,
    I will try this and give you news.

    Thank you for helping.
    Thank you for helping. JCD
    _______________
    SAMBA-LDAP PDC server 13.1--ASUS R900V win8 + 13.1 KDE -- HP DV9350 desktop 12.3 KDE -- acer aspire 7736g win 7 pro - scan EPSON V500 - Brthr HL2150N - Samsung CLP-325W

  8. #8
    Join Date
    Jun 2008
    Location
    South-West France
    Posts
    489

    Default Re: 12.3 - systemd - Forcing a script to run before rsyslog start

    Quote Originally Posted by robin_listas View Post
    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):

    Code:
    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 also this.

    Code:
    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.
    Thank you for helping. JCD
    _______________
    SAMBA-LDAP PDC server 13.1--ASUS R900V win8 + 13.1 KDE -- HP DV9350 desktop 12.3 KDE -- acer aspire 7736g win 7 pro - scan EPSON V500 - Brthr HL2150N - Samsung CLP-325W

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •