Add custom program at Fedora startup

Dear experts,

How to add custom program (/opt/program) to the system  startup.
It may start after httpd, mysqld.

Thank you.
Nusrat NuriyevAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gheistCommented:
You need SysV init header on script like:
#!/bin/sh
#chkconfig: 345

### BEGIN INIT INFO
# Required-Start: $httpd,$mysqld
# Required-Stop: $httpd,mysqld
# Default-Start: 345
# Default-Stop 0126
### END INIT INFO

case $1 in
start)
 /opt/program &
stop)
 killall program
*)
 echo Help tesk
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Manfred BertlManagerCommented:
Hallo,
this resource should help you understandig Systemd (it's short):

https://fedoraproject.org/wiki/Systemd

regards,
fred
0
Nusrat NuriyevAuthor Commented:
Another useful link:
http://fedoraproject.org/wiki/Packaging:SysVInitScript

Guys, do I correctly understand that ,once the script is correclty written and placed to /etc/rc.d/init.d/
so may we say that system reads all scripts in that directory and automatically loaded them at system startup?

chkconfig --add myscript 

Open in new window

gives the following output:
service myscript does not support chkconfig
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Manfred BertlManagerCommented:
Yes, you are correct. You could also add --level <levels> for detailed configuration on what runlevels your script should start or not.

Edit: If it failed, did you write your script as documented in your link?
0
Nusrat NuriyevAuthor Commented:
Yes, you are correct. You could also add --level <levels> for detailed configuration on what runlevels your script should start or not.
On other kind of scripts level option would be handy...
0
gheistCommented:
Can you show headers you added?
My headers kind of allow chkconfig.
0
Nusrat NuriyevAuthor Commented:
Sure

#!/bin/bash
# chkconfig: 345
# description: Description comes here....

### BEGIN INIT INFO
# Required-Start: $sendmail
# Required-Stop: $sendmail
# Default-Start: 345
# Default-Stop: 0126
### END INIT INFO
# Source fuction library
.   /etc/rc.d/init.d/functions

mystart() {
   su -c '/opt/program start' username
}

mystop {
   su -c '/opt/program stop' username
}

case "$1" in
   start)
      mystart
      ;;
   stop)
      mystop
      ;;
   restart)
      mystop
      mystart
      ;;
   *)
      echo "usage: $0 start|stop|restart"
      exit 1
esac
exit 0
0
gheistCommented:
Add this: (i wrote from memory so missed a bit)
# chkconfig: 345 90 10
0
Nusrat NuriyevAuthor Commented:
My script was a compilation of your answer and the tutorial.
But why the previous script worked?
When this script  loaded to the system?

<startpriority> is the "priority" weight for starting the service. Services are started in numerical order, starting at 0.
<endpriority> is the "priority" weight for stopping the service. Services are stopped in numerical order, starting at 0. By default, you should set the <endpriority> equal to 100 - <startpriority>.

Do I correctly understand that the previous my script has used 100 as start priority and 0 as end priority by default?
0
gheistCommented:
Only that it did not work out for me too, and after setting some priorities thare it started to work....
0
Nusrat NuriyevAuthor Commented:
Only that it did not work out for me too, and after setting some priorities thare it started to work....
Let me check it without priorities again.
0
Nusrat NuriyevAuthor Commented:
Haven't you forgotten to do systemctl daemon-reload? (when checking script without priorities)
0
gheistCommented:
It failed at chkconfig --add
0
Nusrat NuriyevAuthor Commented:
Yes, me too. But is it work, in fact? Does the /opt/program starts after reboot?
It works even without checkconfig --add
Let's assume that it's systemctl's internal logic to traverse init.d directory and take files with +x permission whose conform to initscript syntax.
The question should be readdressed to developers.

Also I can see my initscript in the list
systemctl | grep myscript

Open in new window

output
myscript.service
loaded active exited  LSB:Description comes here....
0
gheistCommented:
I dont know. I think random file put in /etc/init.d will not start, but who knows.
0
Nusrat NuriyevAuthor Commented:
But it works :)
I have put the myscript to /etc/rc.d/init.d but /etc/int.d is just symlink to /etc/rc.d/init.d
You can try out.
0
gheistCommented:
I think it is more like "sometimes works"
You might want correct chkconfig operation with orderly shutdown.
0
Nusrat NuriyevAuthor Commented:
Do you mean, if it will not properly shutdown it may not start?
0
gheistCommented:
No i mean if you just drop script in directory there is no guearanty that mysql and httpd are not kicked from under it well before your program stops.
0
Nusrat NuriyevAuthor Commented:
Very reasonable. Will add mysql and httpd immediatly.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux Distributions

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.