Creating custom init scripts

Submitted by Jochus on Thu, 14/01/2010 - 21:12 | Posted in: Linux


Sometimes, it can be useful to organize a lot of shell commands into 1 script. That scripts represents a single, atomic action. For example: starting up a JBoss server.

I've created a custom script to execute my action faster

/etc/init.d/mycustomscript

#! /bin/sh
# /etc/init.d/mycustomscript
#
 
case "$1" in
  start)
    echo "Starting mycustomscript"
    # do
    # some 
    # stuff
    # here
    exit 0
    ;;
  stop)
    echo "Stopping mycustomscript"
    # do
    # some 
    # stuff
    # here    
    exit 0
    ;;
  restart)
    echo "Restarting mycustomscript"
    # do
    # some 
    # stuff
    # here
    exit 0
    ;;    
  *)
    echo "Usage: /etc/init.d/mycstomscript {start|stop|restart}"
    exit 0
    ;;
esac
 
exit 1

Now, you can start/stop/restart your script using:

<a href="mailto:jochen@baileys">jochen@baileys</a> ~ $ sudo /etc/init.d/mycustomscript start

Or to make it even more faster, you can use your bash history: CTRL + R

(reverse-i-search)`sudo /et': sudo /etc/init.d/mycustomscript start

Add new comment

The content of this field is kept private and will not be shown publicly.

Full HTML

  • Lines and paragraphs break automatically.
  • You can caption images (data-caption="Text"), but also videos, blockquotes, and so on.
  • Web page addresses and email addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <bash>, <cpp>, <css>, <html5>, <java>, <javascript>, <php>, <sql>, <xml>. The supported tag styles are: <foo>, [foo].
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.