Service in Linux

Posted on by By Somen Sarkar, in Javascript, Open Source Business Intelligence, Services | 0

Service in Linux

The service are set of programs that run as background process, so it is ready to use anytime by the users. The service gets started when the machine is rebooted automatically.

How to create a Service?
The creation of service is useful when the application is used everytime. This helps the user to save time by frequently starting and stoping the program/application.

We can create a service by writing our own shell scipt and moving the copy of the file in init folder such as /etc/init.d.

What is special about service script in linux?
The shell script that is used for service creation are special script. They have to follow certain coding pattern. The script should have certain function such as start, stop, status, restart etc.

The service script has a header known as LSBscript. A sample of it may look like this

### BEGIN INIT INFO
# Provides: scriptname
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO

Provides: here we need to write the name of the service.
Required-Start: space separated list of program/application that this service required to start itself
Required-Stop: space separated list of program/application that should be stopped when this service is stopped
Default-Start/Default-Stop: The number tells the linux system the runlevels of the program/application the range is generally in between 0 to 6
Short-Description: Simple descript that will be displayed when the service is contacted
Process id: This is a unique number that helps to identify the process. Whenever we start any application in the linux it associate that process with an unique id.

Mechanism that may be followed when writing a service script.
1. The script should be initiated by the root/super user.
2. The script should not contains any harmful script
3. The Process id may be captured by the user so that the status can be determined.
4. The log file can be associated with the program running in the background that may be hlep to debug when application fails

update-rc.d command:
This command helps the user to add/remove services.
To add a script the following command may be run.
update-rc.d -f service_name defaults
To remove the service the following command may be run
update-rc.d service_name remove

When service is added, the application/program can be started/stopped using service command.
eg. sudo service ApplicationName start
eg. sudo service ApplicationName stop

 

logo

Best Open Source Business Intelligence Software Helical Insight is Here

logo

A Business Intelligence Framework

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments