Friday, April 19, 2013

Understanding SysV-style Initscripts in Red Hat Linux

It is often needed to write your own init start/stop script, the following is the minimum requirement for your script to behave as expected. The discussion is based on Red Hat Linux family, other distributions like Debian use LSB (Linux Standard Base Specification) Init Scripts.

Location of the script

/etc/init.d is the well known location, but actually /etc/rc.d/init.d is the real original location. Since /etc/init.d is a hard link to /etc/rc.d/init.d, it makes no difference.

Header of the script

It needs at least 3 lines.  The shell script interpreter (/bin/sh, /bin/bash .. etc), the chkconfig header and script description
#   chkconfig: 345 56 10
#   description: Startup/shutdown script for the Common UNIX 

Body of the script

Obviously, it need  to accept parameter “start”, which  /etc/rc3.d/S* will call  on OS startup and accept parameter “stop”, which /etc/rc0.d/K* script will call on OS shutdown.
The lockfile is often overlooked, it is used to check the existence of the daemon on OS shutdown, otherwise the stop action won’t be called. If you found an issue that a script started on OS startup but never stop properly on shutdown, you need to create lockfile. note: lockfile is not pidfile which contains PID of the process, lockfile is usually a blank file.
lockfile=/var/lock/subsys/$(basename $0)
case $1 in
  [ $? = 0 ] && touch $lockfile
  [ $? = 0 ] && rf –f  $lockfile


It is recommended to import functions in /etc/rc.d/init.d/functions to use ‘daemon’ to startup your application or killproc to shutdown your application instead of reinventing the wheel.

LSB headers

You may see something like this in an init script.
 # Provides: boot_facility_1 [ boot_facility_2 ...]
 # Required-Start: boot_facility_1 [ boot_facility_2 ...]
 # Required-Stop: boot_facility_1 [ boot_facility_2 ...]
 # Should-Start: boot_facility_1 [ boot_facility_2 ...]
 # Should-Stop: boot_facility_1 [ boot_facility_2 ...]
 # Default-Start: run_level_1 [ run_level_2 ...]
 # Default-Stop: run_level_1 [ run_level_2 ...]
 # Short-Description: short_description
 # Description: multiline_description
They are LSB(Linux Standard Base) headers, they are supported by default in Debian and SUSE Linux.
Red Hat Linux supports this by additional package “redhat-lsb” and it is not installed by default, Be warned,50+ dependences need to installed as well.



  1. Thanks for providing this informative information you may also refer.

  2. Superb. I really enjoyed very much with this article here. Really it is an amazing article I had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article.thank you for sharing such a great blog with us. expecting for your.
    Digital Marketing Company in India
    seo Company in India

  3. Good post....thanks for sharing.. very useful for me... Thanks. Complete Set of Desktop on Rent

  4. very very amazing explaintion....many things gather about yourself...yes realy i enjoy it
    SEO Company in India

  5. very very amazing explaintion....many things gather about yourself...yes realy i enjoy it
    seo company in Chennai


  6. تعتبر النظافة أحد أكثر الأمور أهمية في حياتنا لأن النظافة تمنحنا صحة جيده وتبعد عن الكثير من الأمراض المختلفة لذلك وصي الرسول صلى الله عليه وسلم بالنظافة وجعلها من الأمور الدينية التي يجب علي كل مؤمن الاهتمام بها لذلك يجتهد الكثير من أصحاب المنازل في تنظيف المنازل الخاصة بهم أو شركاتهم أو الفلل الخاصة بهم ويسعوا في هذا الأمر ولكن بعد فترة يجدون أن الأمر مرهق ويجدون صعوبة بالغة في الاستمرار بعملية التنظيف ولكن مع شركتنا سهلنا كل الصعب ووضعنا طرق الامان لك ولعائلتك ومنزلك وهذا بوسائل الخبره والمعدات الحديثه الجاهزه تماما

    شركة تنظيف خزانات بالرياض

    شركة تنظيف منازل بالرياض

    شركة عزل خزانات بالخرج

    شركة مكافحه حشرات بالخرج

    شركة تسليك مجاري بالخرج

    شركة عزل اسطح بالخرج

    شركة تنظيف خزانات بالخرج

  7. Arena Infosolution is the best company for the Digital Marketing Internship in Jaipur. Our company offers an internship that gives a good job after completion of the internship which gives a path to your career and makes your future bright in digital marketing.

  8. hy thanks for sharing this information.very helpful and useful thanks

  9. hy thanks for sharing this information.very helpful and useful thanks

  10. hy thanks for sharing this information.very helpful and useful thanks

  11. it is really helpful. the information in this article is satisfied me. And the information it is very interesting. Thanks for this kind of article. thanks