Automatically execute a script or commands after boot finished

General support questions
Post Reply
brucecy92
Posts: 2
Joined: 2020/04/28 02:13:36

Automatically execute a script or commands after boot finished

Post by brucecy92 » 2020/04/28 02:41:26

I am coming from SUSE, and they had a mechanism where if the file /etc/init.d/after.local existed then anything within it was executed after the boot process fully completed. It was convenient because I could do for example "nvidia-smi -pm 1" to set persistence enabled, I had to do this as root because the "persistence" doesn't persist across reboots. And you could do a bunch of other useful things, I would start flexlm license managers.

What is the way to do something like this in RHEL/CentOS 7.6 ?

User avatar
TrevorH
Site Admin
Posts: 33216
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Automatically execute a script or commands after boot finished

Post by TrevorH » 2020/04/28 08:23:11

On RHEL/CentOS there is only /etc/rc.d/rc.local and its associated systemd unit file systemctl status rc-local. The file /etc/rc.d/rc.local contains instructions on how to make it work.

You can also just set up your own systemd unit file to do what you want and have them depend on the services that need to be up and running.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

tunk
Posts: 1206
Joined: 2017/02/22 15:08:17

Re: Automatically execute a script or commands after boot finished

Post by tunk » 2020/04/28 13:01:36

You may want to run yum update to get CentOS 7.8.
Here's an example of a flexlm systemd unit file:

# setup:
#https://gist.github.com/JesterEE/7d9c3d59aa663deeb92f

[Unit]
Description=software1 flexlm license server
After=network.target network.service

[Service]
User=flexlm
Group=flexlm
Environment=LICENSE_FILE=/full/path/to/license.dat
Environment=LOG_FILE=/full/path/to/license.log
WorkingDirectory=/full/path/to
ExecStart=/full/path/to/lmgrd -c $LICENSE_FILE -l $LOG_FILE
Restart=always
RestartSec=30
Type=forking

[Install]
# multiuser cli
WantedBy=multi-user.target

Post Reply