[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Add custom program at Fedora startup

Posted on 2014-08-31
20
Medium Priority
?
240 Views
Last Modified: 2014-09-01
Dear experts,

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

Thank you.
0
Comment
Question by:Nusrat Nuriyev
  • 10
  • 8
  • 2
20 Comments
 
LVL 62

Accepted Solution

by:
gheist earned 2000 total points
ID: 40295234
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
 
LVL 4

Expert Comment

by:Manfred Bertl
ID: 40295316
Hallo,
this resource should help you understandig Systemd (it's short):

https://fedoraproject.org/wiki/Systemd

regards,
fred
0
 

Author Comment

by:Nusrat Nuriyev
ID: 40296444
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:Manfred Bertl
ID: 40296456
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
 

Author Comment

by:Nusrat Nuriyev
ID: 40296460
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
 
LVL 62

Expert Comment

by:gheist
ID: 40296464
Can you show headers you added?
My headers kind of allow chkconfig.
0
 

Author Comment

by:Nusrat Nuriyev
ID: 40296487
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
 
LVL 62

Assisted Solution

by:gheist
gheist earned 2000 total points
ID: 40296506
Add this: (i wrote from memory so missed a bit)
# chkconfig: 345 90 10
0
 

Author Comment

by:Nusrat Nuriyev
ID: 40296533
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
 
LVL 62

Expert Comment

by:gheist
ID: 40296540
Only that it did not work out for me too, and after setting some priorities thare it started to work....
0
 

Author Comment

by:Nusrat Nuriyev
ID: 40296563
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
 

Author Comment

by:Nusrat Nuriyev
ID: 40296565
Haven't you forgotten to do systemctl daemon-reload? (when checking script without priorities)
0
 
LVL 62

Expert Comment

by:gheist
ID: 40296593
It failed at chkconfig --add
0
 

Author Comment

by:Nusrat Nuriyev
ID: 40296612
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
 
LVL 62

Expert Comment

by:gheist
ID: 40296639
I dont know. I think random file put in /etc/init.d will not start, but who knows.
0
 

Author Comment

by:Nusrat Nuriyev
ID: 40296668
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
 
LVL 62

Expert Comment

by:gheist
ID: 40296689
I think it is more like "sometimes works"
You might want correct chkconfig operation with orderly shutdown.
0
 

Author Comment

by:Nusrat Nuriyev
ID: 40296718
Do you mean, if it will not properly shutdown it may not start?
0
 
LVL 62

Expert Comment

by:gheist
ID: 40296787
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
 

Author Comment

by:Nusrat Nuriyev
ID: 40296851
Very reasonable. Will add mysql and httpd immediatly.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

After running Ubuntu some time, you will be asked to download updates for fixing bugs and security updates. All the packages you download replace the previous ones, except for the kernel, also called "linux-image". This is due to the fact that w…
This article will show you step-by-step instructions to build your own NTP CentOS server.  The network diagram shows the best practice to setup the NTP server farm for redundancy.  This article also serves as your NTP server documentation.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

834 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