[CentOS] Running a command at startup

Thu Dec 13 19:38:37 UTC 2018
Kenneth Porter <shiva at sewingwitch.com>

--On Wednesday, December 12, 2018 7:04 PM -0500 Robert Moskowitz 
<rgm at htt-consult.com> wrote:

> So can someone point me to how to make this into a simple systemd service?

I'd first create a utility script (untried code!) like this:

/usr/local/sbin/BlueLedFunction.sh

#!/bin/sh
echo "$1" > /sys/class/leds/blue\:heartbeat/trigger

Then I'd create /etc/systemd/system/BlueLedOff.service with appropriate 
sections to invoke that script with "none" as an argument and to run in 
your desired runlevel. (Take a look at the examples in 
/lib/systemd/system.) Then issue this to have it run at startup:

systemctl enable BlueLedOff

Note that custom unit files go in /etc/systemd/system to avoid having them 
overwritten by distro updates. You can customize existing unit files by 
either copying them from /lib/systemd to /etc/systemd or you can override 
single settings with specially-named subdirectories in /etc/systemd/system. 
See the unit file documentation for details.