I need an initial file to be installed just before system start. To do so I am using a small script which must be run during halt or shutdown but before disks were unmounted.
I have put this script in:/etc/init.d/halt.local
but looking at the console message, I have seen that my script is ran after all disks are unmounted; then it is useless that way .
Any help is welcome.
And the openSUSE version is … ?
It is true you have the openSUSE versions in your signature, but there are two different ones. Thus this does not realy help. Or is this to work in both?
And the winner is …: 12.2
In 12.2 the whole process of starting/stopping is governed by systemd. That is rather new. Maybe other people can help you.
Or you can start yourself in trying to find some documentation on how to add scripts there and how to define when they must be run.
Well … look at following manual page (not yet in 12.2, but applies to it as well): bootup. Unmounting of filesystems is initiated in parallel to stopping running services. Filesystems are unmounted as soon as possible (as long as these are not busy). So strictly speaking during shutdown there is no point in time where you can be sure to have all filesystems mounted.
Could you give more details what your script does and why it needs all filesystems to be mounted? It would help to suggest solution.
See detail here (#6) http://forums.opensuse.org/english/get-technical-help-here/install-boot-login/480499-12-2-place-put-script-ran-startup.html#post2504459
And good running sample : SUSE Paste
I have open this new post because it is not working as it did ( because now during halt all disks are unmounted before the script is ran ).
All what I need is to copy a small include file of 1000 bytes over the current one so the new config will be enable for the next startup.
I can achieve this in other way.
- Just run that small script during startup but before syslog service start; but I don’t know where to put it,
- create a new service and force syslog service to start after that service, ( but need help to do that )
I am going to read your link.
Hello.1°) Have create a service (init-rsyslog.service) using script model from jdmcdaniel3](http://forums.opensuse.org/members/jdmcdaniel3.html)
http://forums.opensuse.org/content/120-systemd-using-after-local-script-opensuse-12-1.html
2°) Have put the path of the script I want to be run before rsyslog start in /etc/init.d/init-rsyslog
3°) Have patch syslog.service by adding init-rsyslog.service in [unit] Requires and After
4°) Have remove initial script in /etc/init.d/halt.local
For now it seems to work.
Syslog.service :
# /lib/systemd/system/syslog.service
#
# This file is part of package klogd.
#
# Copyright (c) 2011 SuSE LINUX Products GmbH, Germany.
# Author: Werner Fink
# Please send feedback to http://www.suse.de/feedback
#
# Description:
#
# Used to start one of the System Logging Service daemons
# depending on the configuration found in /etc/sysconfig/syslog.
#
[Unit]
Description=System Logging Service
Requires=var-run.mount syslog.target init-rsyslog.service
After=var-run.mount init-rsyslog.service
Before=syslog.target
OnFailure=systemd-kmsg-syslogd.service
Conflicts=syslog-ng.service rsyslog.service
#
# Now systemd include the further dependency rules and
# Service section. This include will be automatically
# updated depending on the configuration.
#
.include /run/systemd/syslog.core
[Install]
WantedBy=multi-user.target
init-rsyslog.service :
# 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.
[Unit]
Description=/etc/init.d/init-rsyslog Compatibility
ConditionFileIsExecutable=/etc/init.d/init-rsyslog
[Service]
Type=oneshot
ExecStart=/etc/init.d/init-rsyslog
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
/etc/init.d/init-rsyslog:
#!/bin/sh
#
# Copyright (c) 2010 SuSE LINUX Products GmbH, Germany. All rights reserved.
#
# Author: Werner Fink, 2010
#
# /etc/init.d/init-rsyslog
#
# script with local commands to be executed before rsyslog is started.
#
#
function date2stamp_full () {
date --date "$1" +%Y-%m-%d___%H:%M:%S
}
#
/root/bin/rsyslog_reset_format
#
TIMESTAMP=$(date2stamp_full now)
#
echo "$TIMESTAMP /etc/init.d/init-rsyslog done" >> /var/log/init-rsyslog.log
#
Any comments are welcome.
Adding Before to your service is the same as adding After to syslog.service. Also you could place a link into /etc/systemd/system/syslog.service.requires directory that points to init-rsyslog.service. This is the same as adding Requires to syslog.service (although seems to be undocumented). This allows to specify “forward reference” without need to patch other services.
I understand.
Also you could place a link into /etc/systemd/system/syslog.service.requires directory that points to init-rsyslog.service. This is the same as adding Requires to syslog.service (although seems to be undocumented). This allows to specify “forward reference” without need to patch other services.
Not understood.
Do you mean that I have to do that :
ln /etc/systemd/system/init-rsyslog.service /etc/systemd/system/syslog.service.requires
mkdir /etc/systemd/system/syslog.service.requires
ln -s /etc/systemd/system/init-rsyslog.service /etc/systemd/system/syslog.service.requires
Current systemd added RequiredBy directive in unit files (similar to WantedBy): systemd.unit, which creates these links automatically when you do “systemctl enable unit”.
init-rsyslog.service reside in /etc/systemd/system/multi-user.target.wants so I think the link should be :
ln -s /etc/systemd/system/multi-user.target.wants/init-rsyslog.service /etc/systemd/system/syslog.service.requires
Could you confirm ?
No, that’s wrong.
Ok I return to your recommendation
ln -s /etc/systemd/system/init-rsyslog.service /etc/systemd/system/syslog.service.requires
But the link point to nothing and have a size of 0
For info both kind of link are working but this another story.