Start a service on startup/boot of server (linux)

Requirement of starting a service on boot or on start up is very much required for almost every new service getting installed on linux server. Example is mysqld or httpd which need to be restarted if machine get restarted. Restart of these services just ensure that applications will be back even if server does out of power for few minutes and no technical intervention is required after the re-start.

It is advisable to configure your services to start on boot or on start up of machine.

1. How to start/stop/restart services manually:

You can go to /etc/init.d directory and see here few executable scripts which are responsible of starting services of their related modules/software. e.g. httpd will be located there for starting apache server & mysqld will be there to start mysql database server.

You can directly run these scripts and passing start/stop/restart parameters.

# cd /etc/init.d
#./mysqld start
#./httpd restart

You can use service script to execute these scripts in following way

# service mysqld restart
# service network restart

 

2. How to start services on boot time or start up:

You can do this by first adding service to run levels and then configure its run level so that it starts on boot time. You can use chkconfig for this in following way:

# chkconfig --add httpd
# chkconfig httpd  on --level 2,3,5

Internally a soft link in created in /etc/rc2.d , /etc/rc3.d, /etc/rc5.d directories for /etc/init.d/httpd script and will be invoked under those run levels.

If you are not sure whether your service is part of run levels or not, you can check by following command:

# chkconfig --list mysqld(Your_service_script_name)
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off

It is very essential to use this information so that minor power failure and restart of server should not stop your service till manual intervention.

Most Commented Posts

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

No comments yet.

Leave a comment

(required)

(required)