Jump to content

howto create the 'service' command

Recommended Posts

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


set -e

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


Done.. :)


Example usage:


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)

# a function for the autocompletion of the service command.

 # set some local variables
 local cur prev


 #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 ))
COMPREPLY=( $( compgen -f $cur ))

 return 0

#setup the completion
complete -F _service_fn service

Link to post
Share on other sites
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...