I am trying to execute a shell script on RHEL7.1 when the machine starts. As in ubuntu, Upstart scripts (in /etc/init/) are used to execute any scripts or to start any services at boot time, is there anything equivalent in RHEL 7.1 to upstart?
Asked
Active
Viewed 3,090 times
0
-
Red Hat got rid of upstart (because it was crap). It uses systemd now. – Michael Hampton May 01 '16 at 22:56
2 Answers
1
Let's say you want to execute example.service
at booting time, you'd do:
vi /etc/systemd/system/example.service
with this content:
[Unit]
Description=Example
After=network.target
[Service]
Type=simple
WorkingDirectory=/var/lib/example
ExecStart=/usr/local/bin/example --pid /var/run/example.pid --core unlimited -c /etc/example/example.ini
Restart=always
User=root
Group=root
LimitNOFILE=10240
LimitFSIZE=infinity
[Install]
WantedBy=multi-user.target
Then, just start and enable it:
systemctl start example.service
systemctl enable example.service
-
In my case I've got a shell script to execute, so I need to provide the apth to that shell script in ExecStart=/home/scripts/temp.sh, right? and while rebooting the shell script will get executed? – user3460393 May 02 '16 at 06:12
-
-
Depending on what the script does, you may want `Type=oneshot` instead. – Michael Hampton Jan 03 '18 at 03:08
-1
Add the scrpit in /etc/rc.d/rc.local file, The script will be automatically executed during boot.

BDRSuite
- 400
- 1
- 9