You are not logged in.
EDIT:
Okay I admit it. I did something terrible. I plagiarized the rc-local and re-local-shutdown services from initscripts 2012.08.3-2. All I had to do was add the [Install] sections to both to get them to enable and they work perfectly on my non-sysvinit exclusively systemd install. You can take a look at my script [Solved] Install script for system encrypted pure UEFI/systemd Arch post to see how I installed Arch using the latest Archboot media.
Ordering your scripts can be as simple as listing them in the order you want them executed using multiple ExecStart= directives but only if you use the Type=oneshot option. Note the minus sign '-' before the script path/name. This is necessary because without it should a script fail none of the following ones will get executed and the service will exit prematurely. And if you need to be sure the network is up and running before your run your scripts just add After=network.target to the Unit section.
Now the real fun begins as I model my scripts after these to convert them all to systemd and stop using /etc/rc.local{,-shutdown} completely.
So here they are. The slightly modified plagiarized versions...
/usr/lib/systemd/system/rc-local.service
[Unit]
Description=/etc/rc.local Compatibility
After=network.target
[Service]
Type=oneshot
ExecStart=-/etc/rc.local
ExecStart=-/pathtoyour/script1
ExecStart=-/pathtoyour/script2
TimeoutSec=0
StandardInput=tty
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
/usr/lib/systemd/system/rc-local-shutdown.service
[Unit]
Description=/etc/rc.local.shutdown Compatibility
ConditionFileIsExecutable=/etc/rc.local.shutdown
DefaultDependencies=no
After=rc-local.service basic.target
Before=shutdown.target
[Service]
Type=oneshot
ExecStart=/etc/rc.local.shutdown
StandardInput=tty
RemainAfterExit=yes
[Install]
WantedBy=shutdown.target
Have fun!
Haven't been able to find any workable rc.local and rc.local.shutdown style substitutes for systemd.
The rc.local replacement needs the network to be up and running.
They both need to be able to accept user input.
Nothing fancy but still I can't seem to find anything. Got as far as having the script appear when I boot but it either locks up from the get-go or only allows one character to be entered before it locks up.
Last edited by KairiTech (2012-09-08 11:48:07)
Offline
rc-local.service
[unit]
Description=/etc/rc.local Compatibility
[Service]
Type=oneshot
ExecStart=/etc/rc.local
TimeoutSec=0
StandardInput=tty
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
Also=rc-local-shutdown.service
rc-local-shutdown.service
[Unit]
Description=/etc/rc.local.shutdown Compatibility
After=rc-local.service
[Service]
Type=oneshot
ExecStart=/etc/rc.local.shutdown
StandardInput=tty
RemainAfterExit=yes
[Install]
WantedBy=shutdown.target
Also=rc-local.service
You know I was able to find this in just a couple minutes perusing the wiki...
Offline
Thanks. I was missing 'RemainAfterExit=yes' in rc-local.service.
No sign of rc-local-shutdown.service when I shutdown though.
Offline
'ExecStop=/etc/rc.local.shutdown' didn't seem to make a difference.
By "don't use" do you mean not to run any custom scripts at boot or shutdown?
Or do you mean do not call /etc/rc.local or /etc/rc.local.shutdown from the service but instead call my custom script directly? "A rose by any other name..." and all that. Though I suspect it's more about a sow's ear and a purse.
Here's one of the scripts I want to run on boot:
if [[ ! `ping -c1 google.ca 2>&1 | grep unknown` ]]
then
MESSAGE="Synchronizing time..." ; NOTIFY="INFO" ; . /opt/myArch/notify.sh
y=`{ ntpd -qg; hwclock -w ; }`
echo ${y}
logger "myArch: ${y}"
else
echo "Yikes! No network."
logger "myArch: Network NOT available for time Synchronization"
fi
Last edited by KairiTech (2012-09-02 03:52:54)
Offline
I think the preferred (yet still considered a hack) method is to put custom scripts in /usr/lib/systemd/system-shutdown... there is also a system-sleep, which is where I set up netcfg to reconnect after wake.
Edit: I'm curious, what is the advantage of your custom script for time synchronization? I see that you are ultimately using ntpd, but in a very round-about way... not saying it is wrong, but I am just wondering...
Last edited by WonderWoofy (2012-09-02 03:52:52)
Offline
'ExecStop=/etc/rc.local.shutdown' didn't seem to make a difference.
By "don't use" do you mean not to run any custom scripts at boot or shutdown?
No, I mean that there's a better way.
Here's one of the scripts I want to run on boot:
if [[ ! `ping -c1 google.ca 2>&1 | grep unknown` ]] then MESSAGE="Synchronizing time..." ; NOTIFY="INFO" ; . /opt/myArch/notify.sh y=`{ ntpd -qg; hwclock -w ; }` echo ${y} logger "myArch: ${y}" else echo "Yikes! No network." logger "myArch: Network NOT available for time Synchronization" fi
You need absolutely none of this. This is what ntpd.service does on its own. It'll wait for the network to come up before starting (and doing an initial sync with --panicgate).
Offline
KairiTech wrote:Here's one of the scripts I want to run on boot:
if [[ ! `ping -c1 google.ca 2>&1 | grep unknown` ]] then MESSAGE="Synchronizing time..." ; NOTIFY="INFO" ; . /opt/myArch/notify.sh y=`{ ntpd -qg; hwclock -w ; }` echo ${y} logger "myArch: ${y}" else echo "Yikes! No network." logger "myArch: Network NOT available for time Synchronization" fi
You need absolutely none of this. This is what ntpd.service does on its own. It'll wait for the network to come up before starting (and doing an initial sync with --panicgate).
That is what I thought.... just thought the OP might be in on some secret I wasn't aware of.
Offline
I think the preferred (yet still considered a hack) method is to put custom scripts in /usr/lib/systemd/system-shutdown... there is also a system-sleep, which is where I set up netcfg to reconnect after wake.
Edit: I'm curious, what is the advantage of your custom script for time synchronization? I see that you are ultimately using ntpd, but in a very round-about way... not saying it is wrong, but I am just wondering...
Perhaps ntpd was a poor example for what I'm trying to accomplish which is to run custom scripts (any custom script) at boot or shutdown.
But to the point...if it's a hack it's a hack..so be it. My question is what is (or is going to be) the acceptable alternative?
Offline
falconindy wrote:KairiTech wrote:Here's one of the scripts I want to run on boot:
if [[ ! `ping -c1 google.ca 2>&1 | grep unknown` ]] then MESSAGE="Synchronizing time..." ; NOTIFY="INFO" ; . /opt/myArch/notify.sh y=`{ ntpd -qg; hwclock -w ; }` echo ${y} logger "myArch: ${y}" else echo "Yikes! No network." logger "myArch: Network NOT available for time Synchronization" fi
You need absolutely none of this. This is what ntpd.service does on its own. It'll wait for the network to come up before starting (and doing an initial sync with --panicgate).
That is what I thought.... just thought the OP might be in on some secret I wasn't aware of.
ntpd was a bad example. Just think of any custom script that needs to be run at boot or shutdown.
Last edited by KairiTech (2012-09-02 04:04:30)
Offline
Ok... and my point is that there's a better way than just dropping it in a singular file and executing them in serial.
So if I understand you correctly each custom script should have its own service?
Offline
I don't think he is necessarily telling you that it *should* be a service, but rather that having an all purpose scratchpad script like rc.local is messy and rather less than an elegant solution. Hence support for it was dropped, seemingly in favor of making use of the tools that systemd provides (which is many).
Offline
I have another example of rc.local which is mainly about configuring power saving etc etc on a netbook
hdparm -B254 /dev/sda
grep -q '0' /sys/class/power_supply/ADP1/online && P="powersave" || P="ondemand"
cpupower -c all frequency-set -g "$P"
echo 1500 > /proc/sys/vm/dirty_writeback_centisecs
/usr/sbin/iw dev wlan0 set power_save on
echo '0' > '/proc/sys/kernel/nmi_watchdog'
echo '1' > '/sys/module/snd_hda_intel/parameters/power_save'
echo 'auto' > '/sys/bus/pci/devices/0000:00:00.0/power/control'
echo 'auto' > '/sys/bus/pci/devices/0000:00:02.0/power/control'
echo 'auto' > '/sys/bus/pci/devices/0000:00:1c.0/power/control'
echo 'auto' > '/sys/bus/pci/devices/0000:00:1b.0/power/control'
echo 'auto' > '/sys/bus/pci/devices/0000:00:1d.0/power/control'
echo 'auto' > '/sys/bus/pci/devices/0000:00:1d.1/power/control'
echo 'auto' > '/sys/bus/pci/devices/0000:00:1d.2/power/control'
echo 'auto' > '/sys/bus/pci/devices/0000:00:1d.3/power/control'
echo 'auto' > '/sys/bus/pci/devices/0000:00:1d.7/power/control'
echo 'auto' > '/sys/bus/pci/devices/0000:00:1f.2/power/control'
echo 'auto' > '/sys/bus/pci/devices/0000:00:1f.3/power/control'
echo 'auto' > '/sys/bus/pci/devices/0000:01:00.0/power/control'
echo 'auto' > '/sys/bus/pci/devices/0000:02:00.0/power/control'
echo 'auto' > '/sys/bus/pci/devices/0000:00:1c.1/power/control'
/usr/sbin/ethtool -s eth0 wol d
what is the systemd way of doing this sort of thing?
Also where should local units be put so that they can be enabled/disabled etc. If I put them in /usr/lib/systemd/system won't they interfere with pacman?
Offline
Hi,
Your power saving commands belong in a custom service with an appropriate name, the echo lines could also go in tempfiles.d or udev rules.
cpupower has its own service, the configuration is in /etc/conf.d/cpupower
Custom units belong in /etc/systemd/system
Last edited by progandy (2012-09-02 11:23:32)
| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |
Offline
Hi,
Your power saving commands belong in a custom service with an appropriate name, the echo lines could also go in tempfiles.d or udev rules.
cpupower has its own service, the configuration is in /etc/conf.d/cpupower
Custom units belong in /etc/systemd/system
One thing I have been still trying to figure out is the hdparm. I know that there must be a better solution than the ghetto/ half-@$$ed service file I made for it. Also I don't think it is not persistent between suspends (which I can fix with systemd-sleep). My first thought was to use hdparm.conf, but it seems that feature is not included in the arch package.
Offline
Getting back to the topic of my post:
So far I have what seems to be a working rc.local style service that I intend to use as a model to convert my scripts to systemd.
/usr/lib/systemd/system/rc-local.service
[unit]
Description="/etc/rc.local Compatibility"
[Service]
Type=oneshot
ExecStart=/etc/rc.local
TimeoutSec=0
StandardInput=tty
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
Can't seem to get the rc.local.shutdown style service to work though.
/usr/lib/systemd/system/rc-local-shutdown.service
[Unit]
Description="/etc/rc.local.shutdown Compatibility"
After=rc-local.service
[Service]
Type=oneshot
ExecStart=/etc/rc.local.shutdown
StandardInput=tty
RemainAfterExit=yes
[Install]
WantedBy=shutdown.target
Last edited by KairiTech (2012-09-02 17:57:10)
Offline
One thing I noticed after using a copy of the above is that it complains about the spelling of 'unit'; it should be Unit. I don't think that can affect the shutdown service though.
Offline
One thing I noticed after using a copy of the above is that it complains about the spelling of 'unit'; it should be Unit. I don't think that can affect the shutdown service though.
I noticed that after the post but it is corrected now.
Offline