Startup script in RedHat

For those scripts saved under /etc/rc.d/init.d in RedHat, will it start automatically, or I still need to issue command "service Myscript start" to start it,

Tks
AXISHKAsked:
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.

Mark BullockQA Engineer IIICommented:
If you are using init.d, they will start automatically. That's for older versions of red hat.

The latest version of red hat uses systemd.

This page tells you the differences and how to transition from init to systemd.
https://access.redhat.com/articles/754933
0
AXISHKAuthor Commented:
For those of the script (daemon), how to convert it to suppor the new format :
systemctl start myscript.service

Is there any format to follow for the .service file ?  For the script such as xxx.service, xxxx.mount, is there any format that I need to follow ?

I have attached a standard service script in my current RedHat :

# chkconfig: 2345 20 80
# description: Description comes here....

# Source function library.
. /etc/init.d/functions

start() {
    # code to start app comes here
    # example: daemon program_name &
}

stop() {
    # code to stop app comes here
    # example: killproc program_name
}

case "$1" in
    start)
       start
       ;;
    stop)
       stop
       ;;
    restart)
       stop
       start
       ;;
    status)
       # code to check status of app comes here
       # example: status program_name
       ;;
    *)
       echo "Usage: $0 {start|stop|status|restart}"
esac

exit 0



Tks
0
Mark BullockQA Engineer IIICommented:
Here's a simple example for a daemon program.
touch /etc/systemd/system/program_name.service
chmod 664 /etc/systemd/system/program_name.service

Open in new window

Replace name with a name of the service to be created. Note that file does not need to be executable.
Open the name.service file created in the previous step, and add the service configuration options.

 The following is an example unit configuration for a network-related service:
[Unit]
Description=service_description
After=network.target

[Service]
ExecStart=path_to_executable
Type=forking
PIDFile=path_to_pidfile

[Install]
WantedBy=default.target

Open in new window


For details, this page is helpful. https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/sect-Managing_Services_with_systemd-Unit_Files.html
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
gheistCommented:
systemd in CentOS7 supports SystemV init scripts exactly like upstart in CentOS6, no need to rewrite in some brain damage that will not run on any other system in future.

init.d scripts will work - any executable file in init.d directory will be started and stopped with system, probably you can improve over that by setting proper runlevel headers in your script and using chkconfig --add service and service start/stop
0
AXISHKAuthor Commented:
Tks
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

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.