Discussion:
How to modify files from within systemd *.service? (for example using /bin/echo and stdout redirection)
(too old to reply)
Peter Lemenkov
2012-05-26 06:27:23 UTC
Permalink
Hello All!

I've got Apple Mac keyboard which behaviour depends on a value stored
in /sys/module/hid_apple/parameters/fnmode file (default is "1").
Before systemd I did the following - I added the "echo 2 >
/sys/module/hid_apple/parameters/fnmode" line to the end of
/etc/rc.d/rc.local . Recently I tried to do the same using native
systemd *.service file and quickly created the following one:

======================

[Unit]
Description=Fix Apple Keyboard Fn Behaviour

[Service]
Type=oneshot
RemainAfterExit=yes
ConditionPathExists=/sys/module/hid_apple/parameters/fnmode
ExecStart=/bin/echo 2 > /sys/module/hid_apple/parameters/fnmode

[Install]
WantedBy=multi-user.target

======================

Unfortunately it doesn't work at all. Although systemctl tells me that
everything is ok, the contents of the
/sys/module/hid_apple/parameters/fnmode file remains intact. After a
brief examination I found that I just can't simply redirect stdout to
the file (e.g. if I change ExecStart to someting like this
"ExecStart=/bin/echo 2 > /tmp/test.txt" then the file /tmp/test.txt"
will not be created).

So questions are

* Can I somehow modify the given file from systemd files w/o too much
efforts? "Too much" means w/o writing simple console utility only with
systemd+shell means.
* How to restore the original ">" and "<" behaviour if required?
--
With best regards, Peter Lemenkov.
shawn
2012-05-26 06:34:06 UTC
Permalink
Post by Peter Lemenkov
Hello All!
I've got Apple Mac keyboard which behaviour depends on a value stored
in /sys/module/hid_apple/parameters/fnmode file (default is "1").
Before systemd I did the following - I added the "echo 2 >
/sys/module/hid_apple/parameters/fnmode" line to the end of
/etc/rc.d/rc.local . Recently I tried to do the same using native
I have the same keyboard. You are doing this the hard (and slow) way.

just add

options hid_apple fnmode=2

to

/etc/modprobe.d/hid_apple.conf

and then run:

update-initramfs -u
or whatever the equivilent is for dracut

or see here https://help.ubuntu.com/community/AppleKeyboard

(applicable to all distributions)
Post by Peter Lemenkov
======================
[Unit]
Description=Fix Apple Keyboard Fn Behaviour
[Service]
Type=oneshot
RemainAfterExit=yes
ConditionPathExists=/sys/module/hid_apple/parameters/fnmode
ExecStart=/bin/echo 2 > /sys/module/hid_apple/parameters/fnmode
[Install]
WantedBy=multi-user.target
======================
Unfortunately it doesn't work at all. Although systemctl tells me that
everything is ok, the contents of the
/sys/module/hid_apple/parameters/fnmode file remains intact. After a
brief examination I found that I just can't simply redirect stdout to
the file (e.g. if I change ExecStart to someting like this
"ExecStart=/bin/echo 2 > /tmp/test.txt" then the file /tmp/test.txt"
will not be created).
So questions are
* Can I somehow modify the given file from systemd files w/o too much
efforts? "Too much" means w/o writing simple console utility only with
systemd+shell means.
* How to restore the original ">" and "<" behaviour if required?
--
-Shawn Landden
Joachim
2012-05-26 07:19:23 UTC
Permalink
Hi Peter,

Shawns way to setup the keyboard is probably the best, but to answer the
Post by Peter Lemenkov
* How to restore the original ">" and "<" behaviour if required?
It doesnt work because redirects are a shell feature and systemd starts
programs without the help of a shell. So this line

ExecStart=/bin/echo 2 > /tmp/test.txt

would need to be transformed into

ExecStart=/bin/bash -c 'echo 2 > /tmp/test.txt'

untested, but should work.
Peter Lemenkov
2012-05-26 07:38:49 UTC
Permalink
Hello!
Post by Joachim
It doesnt work because redirects are a shell feature and systemd starts
programs without the help of a shell. So this line
ExecStart=/bin/echo 2 > /tmp/test.txt
would need to be transformed into
ExecStart=/bin/bash -c 'echo 2 > /tmp/test.txt'
untested, but should work.
Thanks - this indeed works. I just tested it.
--
With best regards, Peter Lemenkov.
Peter Lemenkov
2012-05-26 07:37:45 UTC
Permalink
Hello!
Post by shawn
I have the same keyboard. You are doing this the hard (and slow) way.
just add
options hid_apple fnmode=2
to
/etc/modprobe.d/hid_apple.conf
I am aware of this method. Unfortunately (and quite surprisingly it is
never worked for me (for whatever reasons). I tried it again and it
still doesn't work. Perhaps Fedora powerpc kernel config is different
in some aspects.
--
With best regards, Peter Lemenkov.
Canek Peláez Valdés
2012-05-26 13:46:12 UTC
Permalink
Post by Peter Lemenkov
Hello!
Post by shawn
I have the same keyboard. You are doing this the hard (and slow) way.
just add
options hid_apple fnmode=2
to
/etc/modprobe.d/hid_apple.conf
I am aware of this method. Unfortunately (and quite surprisingly it is
never worked for me (for whatever reasons). I tried it again and it
still doesn't work. Perhaps Fedora powerpc kernel config is different
in some aspects.
Have you tried to add hid_apple.fnmode=2 to your kernel command line in
Grub? I don't use modules, I compile everything I need inside my kernel,
and this is the only way I have to pass parameters to my "modules".

Regards.
--
Canek Peláez Valdés
Posgrado en Ciencia e Ingeniería de la Computación
Universidad Nacional Autónoma de México
Peter Lemenkov
2012-05-26 14:50:04 UTC
Permalink
Hello!
Post by Canek Peláez Valdés
Have you tried to add hid_apple.fnmode=2 to your kernel command line in
Grub? I don't use modules, I compile everything I need inside my kernel, and
this is the only way I have to pass parameters to my "modules".
Thanks! It works now even w/o systemd service.
--
With best regards, Peter Lemenkov.
shawn
2012-05-26 17:57:11 UTC
Permalink
Post by Peter Lemenkov
Hello!
Post by shawn
I have the same keyboard. You are doing this the hard (and slow) way.
just add
options hid_apple fnmode=2
to
/etc/modprobe.d/hid_apple.conf
I am aware of this method. Unfortunately (and quite surprisingly it is
never worked for me (for whatever reasons). I tried it again and it
still doesn't work. Perhaps Fedora powerpc kernel config is different
in some aspects.
It is probably not working, because you havn't updated the file inside
your initrd, and the module is getting loaded before you have switched
to the root filesystem on boot. If you plugged it in after boot it would
probably work.
--
-Shawn Landden
Peter Sztan
2012-05-26 20:20:52 UTC
Permalink
The other way to do it would be with a tmpfiles.d snippet,
the 'w' type was made for this exact purpose (writing values to /sys ala sysctl)
see http://www.freedesktop.org/software/systemd/man/tmpfiles.d.html and
http://cgit.freedesktop.org/systemd/systemd/commit/?id=31ed59c51126fce7d958c188772a397e2a1ed010
Post by shawn
Post by Peter Lemenkov
Hello!
Post by shawn
I have the same keyboard. You are doing this the hard (and slow) way.
just add
options hid_apple fnmode=2
to
/etc/modprobe.d/hid_apple.conf
I am aware of this method. Unfortunately (and quite surprisingly it is
never worked for me (for whatever reasons). I tried it again and it
still doesn't work. Perhaps Fedora powerpc kernel config is different
in some aspects.
It is probably not working, because you havn't updated the file inside
your initrd, and the module is getting loaded before you have switched
to the root filesystem on boot. If you plugged it in after boot it would
probably work.
--
-Shawn Landden
_______________________________________________
systemd-devel mailing list
http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Harald Hoyer
2012-05-29 09:45:32 UTC
Permalink
Post by shawn
Post by Peter Lemenkov
Hello All!
I've got Apple Mac keyboard which behaviour depends on a value stored
in /sys/module/hid_apple/parameters/fnmode file (default is "1").
Before systemd I did the following - I added the "echo 2 >
/sys/module/hid_apple/parameters/fnmode" line to the end of
/etc/rc.d/rc.local . Recently I tried to do the same using native
I have the same keyboard. You are doing this the hard (and slow) way.
just add
options hid_apple fnmode=2
to
/etc/modprobe.d/hid_apple.conf
update-initramfs -u
or whatever the equivilent is for dracut
or see here https://help.ubuntu.com/community/AppleKeyboard
(applicable to all distributions)
Adding "hid_apple.fnmode=2" to the kernel command line might also work.
Peter Sztan
2012-05-26 08:09:48 UTC
Permalink
Post by Peter Lemenkov
Hello All!
I've got Apple Mac keyboard which behaviour depends on a value stored
in /sys/module/hid_apple/parameters/fnmode file (default is "1").
The other way to do it would be with a tmpfiles.d snippet,
the 'w' type was made for this purpose
see http://www.freedesktop.org/software/systemd/man/tmpfiles.d.html
Loading...