0

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?

1
  • Red Hat got rid of upstart (because it was crap). It uses systemd now. May 1, 2016 at 22:56

2 Answers 2

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
3
  • 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? May 2, 2016 at 6:12
  • Yeah, that's right
    – sysfiend
    May 2, 2016 at 6:52
  • Depending on what the script does, you may want Type=oneshot instead. Jan 3, 2018 at 3:08
-1

Add the scrpit in /etc/rc.d/rc.local file, The script will be automatically executed during boot.

1
  • That works in RHEL6, not 7
    – sysfiend
    May 2, 2016 at 9:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .