You are not logged in.

#1 2012-12-08 17:55:12

fredre
Member
Registered: 2009-12-18
Posts: 45

how do I run a command at startup with systemd?

I need to run

# hdparm -B 255 /dev/sda

at startup. I used to do this in /etc/rc.local using initscrips. How do I do this using systemd?

Offline

#2 2012-12-08 18:09:19

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,597
Website

Re: how do I run a command at startup with systemd?


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#3 2012-12-28 22:50:46

KairiTech
Member
From: Toronto, Canada
Registered: 2011-06-04
Posts: 275

Re: how do I run a command at startup with systemd?

This is what I did to replace /etc/rc.local{,.shutdown} with what I wanted run at startup{,.shutdown}.

Hope it helps.

Offline

#4 2012-12-29 01:15:17

renegat
Member
From: Europe
Registered: 2012-12-28
Posts: 88

Re: how do I run a command at startup with systemd?

Spend myself hours on solving this... without luck!

One way which does also NOT work:

Create a file i.e.
hdparm.sh
in /etc/profile.d/
put the hdparm commando in the file
echo 'hdparm -B254 /dev/sdX' > /etc/profile.d/hdparm.sh
make it executable (755)
restart and check hdparm -B /dev/sdX

BTW: Default was OFF (255) which did not stop SAMSUNG HM641JI from parking heads every 8 sec.
-B254 stopps klicking entirely for this drive.

Isn't there a suitable simple (kiSs?) solution? I've tried to put this in neraly every .profile *rc and everywhere -

And according to the following post:
I'm far away from understanding such hacks. Though I was in the Newbie-Corner....

Last edited by renegat (2012-12-29 11:50:25)

Offline

#5 2012-12-29 01:21:46

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: how do I run a command at startup with systemd?

How about something like this.  Use udev to determine if a given disk is rotational or not, and then run that hdparm command on the rotational ones.

So make a file /etc/udev/rules.d/75-hdparm.rules that includes:

ACTION=="add", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="1", RUN+="/sbin/hdparm -B 254 /dev/$kernel" 

I figure that this way you are not unecessarily changing the setting on SSDs.

Offline

#6 2012-12-29 11:48:43

renegat
Member
From: Europe
Registered: 2012-12-28
Posts: 88

Re: how do I run a command at startup with systemd?

Made it! The WonderWoofy's answer was the solution:

I still got no idea, how it works, but it works!
Thank you alot - think I've got somthing to read about 'udev'...

Last edited by renegat (2012-12-29 12:33:41)

Offline

#7 2012-12-29 12:40:40

patroclo7
Member
From: Bassano del Grappa, ITALY
Registered: 2006-01-11
Posts: 915

Re: how do I run a command at startup with systemd?

Another, less general, solution. Create a /usr/local/sbin/rc.local script with the following content:

#!/bin/bash
#
# /usr/local/sbin/rc.local: Local multi-user startup script.
hdparm -B254 /dev/sda

You can add whatever you want to be run at boot with root privileges.
Make it executable:

chmod +x /usr/local/sbin/rc.local

Create a service file for rc.local in /etc/systemd/system/rc-local.service with the following content:

[Unit]
Description=/etc/rc.local Compatibility
ConditionFileIsExecutable=/usr/local/sbin/rc.local

[Service]
Type=oneshot
ExecStart=/usr/local/sbin/rc.local
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99

[Install]
WantedBy=multi-user.target

Enable it:

#systemctl enable rc-local

Reboot.

Last edited by patroclo7 (2012-12-29 12:41:25)


Mortuus in anima, curam gero cutis

Offline

#8 2012-12-29 16:05:06

renegat
Member
From: Europe
Registered: 2012-12-28
Posts: 88

Re: how do I run a command at startup with systemd?

Looks interesting too, thank you!

I've tried likewise way by creating

/etc/systemd/system/hdplccs.service :

[Unit]
Description=hdparm_load_cycle_count_save

[Service]
Type=oneshot
ExecStart=/sbin/hdparm -B254 /dev/sda
TimeoutSec=0
StandardInput=tty
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

made it executable and tried to start
systemctl start hdplccs.service

which did also not work.

Will try your way next installation.

Thank you all and have a Happy New Year

renegat

Offline

#9 2012-12-29 16:21:13

patroclo7
Member
From: Bassano del Grappa, ITALY
Registered: 2006-01-11
Posts: 915

Re: how do I run a command at startup with systemd?

I do not know what is actually wrong with your service file, but for sure there is no need to make it executable. Alas or luckily according to the points of view, it is not a script (but can be used to run a script)...


Mortuus in anima, curam gero cutis

Offline

#10 2012-12-30 20:17:58

renegat
Member
From: Europe
Registered: 2012-12-28
Posts: 88

Re: how do I run a command at startup with systemd?

Hi@ All!

I've tried to get power management work on my RTL8187SE Wireless LAN Controller.

# iwconfig wlan0 power on

works fine [edit] for some seconds, then connection is lost!
RTL8187SE is known for such issues due to 'too' aggressive HW-PM - i have been warned ;-)
[/edit]
but ...same procedure as last time... how to get it set automatic at boot?

Tried creating : /etc/udev/rules.d/wlan0_power_save.rules

with

ACTION=="add", SUBSYSTEM=="net", KERNEL=="wlan0", RUN+="/usr/sbin/iwconfig wlan0 power on"

which does not work cause 'iwconfig wlan0' seems to be executed while 'power on' produces an error.

The way given here depends on 'iw' - but 'iw' does not work due to missing 'nl80211'... *confused*

Any ideas?

renegat

Edit:
'iw' is the 'newer' set of wireless-tools - and does not support such old cards as mine.

Last edited by renegat (2013-02-16 09:43:35)

Offline

#11 2012-12-30 21:05:20

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: how do I run a command at startup with systemd?

renegat, I am glad to ahve helped with the hdparm issue.  But this last post is a totally different issue.  You should probably start a new thread, else your question is likely to just get lost in the mix.

I am also glad to see that you have apparently actually gone out and read some information regarding the answer I gave above.  It is nice to see a newcomer actually have the desire to learn rather than expect spoon feeding.  Unfortunatley we have been seeing way too much of that lately.  Your attitude is a breath of fresh air.  Start a new thread and I am sure you will get some help.

Offline

Board footer

Powered by FluxBB