Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how to run my script during boot in rhel 7

Posted on 2016-10-07
14
Medium Priority
?
2,077 Views
Last Modified: 2016-10-21
I have RHEL 7.2 and not able to run my scirpt wile reboot actually when i am creating a soft link of my script then it wont work but if i am creating a file in init.d it works. please help with the correct process in rhel 7.2
0
Comment
Question by:The Rock
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +3
14 Comments
 
LVL 12

Expert Comment

by:andreas
ID: 41833245
Another thing to think of, maybe its a workable solution for your script.

create a cron job that runs once at boot time and execute the script there...
0
 

Author Comment

by:The Rock
ID: 41833352
Thanks but have a look at below link if you understand something because i tried but not a sucess with systemd. Might be you have any idea on this:

https://access.redhat.com/articles/754933

thanks
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 41833357
make sure that:

- you have SXXscriptname in the right run level dir. Name should start with S and XX is a sequence number. e.g. S88myscript
- all file systems are already mounted
- use full path names for files, folders, commands, etc
- set necessary env. variables
- if you need to run commands with specific username then use us - username command
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 62

Assisted Solution

by:gheist
gheist earned 500 total points
ID: 41833734
systemd needs pinching with chkconfig:
chkconfig --add name_of_init_script
chkconfig name_of_init_script on
service name_of_init_script start

upstart in RHEL6 rund anything you throw in /etc/init.d

Or add a script without init.d decorations in /etc/rc.local
0
 
LVL 80

Assisted Solution

by:arnold
arnold earned 500 total points
ID: 41836274
On what does this script depend and what you expect it todo?
Adding the script to /etc/init.d/ and using chkconfig setting to make sure it is executed after all the resources that it needs are loaded.

Look at anothe script
#chkconfig 234 80 20
Ir something like that when chkconfig as gheist referenced us used, it sets the script to run at runlevel 2, 3, 4 using 80 meaning everything before 80 has to be executed/started before this script runs. 20 tells/sets the order of terminating process on poweroff/restart/halt, etc.

You could also add the script command in the rc.local file which will run it once when the system loaded completely.

Your issue might be that you are scheduling its run too early resulting in a failure because a component it needs is still unavailable.
I.e. Trying to pull some data from network, but the network setup gas not yet ran. Access an NFS share, before the NFS components are brought up.

You can set  to run from /etc/inittab but be cautious of the settings, as you may trigger the run if the repetitively......
0
 

Author Comment

by:The Rock
ID: 41836488
Tried all it works on rhel 6 but dont know why it doesnt works while reboot on rhel 7.2 :(
0
 
LVL 80

Expert Comment

by:arnold
ID: 41836669
What does the item you want to run at bootup supposed to do?
Where are you trying and what is happening.

Are saying you create an init.d script and link it out, but after the first reboot all those parameters are gone?
0
 

Author Comment

by:The Rock
ID: 41836700
No I have just create a simple script let say creating a file and directory using touch and mkdir full path of command under init.d . only diffrence is script is located under /opt and softlink is in under init.d

but it wont work.

if i place original file under init.d not a softlink then it works even after reboot
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 41836904
If they are both on same filesystem then create hardlink instead of softlink
0
 
LVL 80

Expert Comment

by:arnold
ID: 41837131
The issue might be that /opt is unavailable when you try to run the script?
can you post df -k
0
 
LVL 27

Accepted Solution

by:
skullnobrains earned 1000 total points
ID: 41841767
init scripts are expected to provide standard options such as start/stop/reload... and there are tools to configure systemV. soft or hard linking a script in init is most definitely not the way to go.

but there is no reason to run a script through init.d which is meant to run daemons unless you really need your script to start early during the boot process.

in your case, you apparently run into the reverse problem. this is solvable in init.d by addding required dependencies with something like "After=local-fs.target" in a yourscript.target file. ( I feel like throwing whenever i see linuxian service dependencies config whatever the distribution as long as it has been based on SysV at any point in time )

stick a file in /etc/cron.d or in the regular crontab and schedule using "@reboot" instead of the usual 5 first fields : this will be simpler and easier to maintain. and this works fine and in the exact same way on any unix-like os
1
 

Author Comment

by:The Rock
ID: 41849814
Hello Skullnobrains,

Thanks your cron @reboot option looks good but i dont know about syntax never used it could you please help it how to do it if my script is /opt/abc.sh how to run it and what entry need to make it ?

thank you
0
 
LVL 27

Expert Comment

by:skullnobrains
ID: 41849998
in the regular crontab, something like this should do

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
@reboot sh /opt/abc.sh > /var/log/output.log 2>&1

Open in new window


if you're using a file in cron.d you'd need to add the username in front of @reboot

i added a standard path as crontab use a default path which lacks many commands

have a look at "man 5 crontab"
0
 

Author Closing Comment

by:The Rock
ID: 41854805
Thanks all for your suggestions. Appreciated
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question