linux-noob.com/forums: howto create the 'service' command - linux-noob.com/forums

Jump to content

Page 1 of 1

howto create the 'service' command aimed at gentoo

#1 User is offline   znx

  • Linux-Noob GURU
  • PipPipPipPipPipPipPipPip
  • View blog
Group:
Members
Posts:
1,220
Joined:
21-March 05

Posted 27 July 2005 - 12:49 PM

I've always sort of liked the 'service' command that comes with redhat, so I created my own:

Create a file (as root) /usr/sbin/service
CODE
#!/bin/sh

set -e

/etc/init.d/$1 $2 $3


Done.. smile.gif

Example usage:

CODE
service mysql start
service mysql stop
service sshd start


Always one for making completions I did this too, mind this is gentoo aimed a little (the secondary option)

Place this in ~/.bashrc or /etc/bash.bashrc (or /etc/bash_completion.d/service for gentoo users)
CODE
# a function for the autocompletion of the service command.

_service_fn()
{
  # set some local variables
  local cur prev

  COMPREPLY=()
  cur=${COMP_WORDS[COMP_CWORD]}
  prev=${COMP_WORDS[COMP_CWORD-1]}

  #if only one completion or a option is being requested
  #then complete against various options
  if [ $COMP_CWORD -eq 1 ]; then
    COMPREPLY=( $( compgen -W "$(ls /etc/init.d)" $cur ))
  elif [ $COMP_CWORD -eq 2 ]; then
    COMPREPLY=( $( compgen -W "start stop restart pause zap status ineed iuse needsme usesme broken" $cur ))
  else
    COMPREPLY=( $( compgen -f $cur ))
  fi

  return 0
}

#setup the completion
complete -F _service_fn service

Bye
0

Page 1 of 1

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users





The G2-style Tux and the header images using them are licensed under Creative Commons BY-NC-SA. The G2-style Tux images are all from http://crystalxp.net.
Thanks to users kami23, lilitux, iva, overlord59, whidou, brightknight, emulienfou on the Crystal XP Tux Factory site.