[systemd-devel] How to modify files from within systemd *.service? (for example using /bin/echo and stdout redirection)

shawn shawnlandden at gmail.com
Fri May 25 23:34:06 PDT 2012


On Sat, 2012-05-26 at 02:27 -0400, Peter Lemenkov wrote: 
> 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:

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) 
> 
> ======================
> 
> [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



More information about the systemd-devel mailing list