Service Process Start, Service Start Process

I may be slightly dyslexic as I am constantly typing service start nginx or service restart mysqld when interacting with services controlled via init.d. Rather than making myself constantly retype it I created a shell script that would reverse it for me, and then just linked the script to the various commands I wanted to use service with.

#!/bin/sh
# description:  This reverses the last argument since I screw it up all the time.
# processname:  service-reverser

EXEC=`echo "$0 $1" | sed -e 's/\/etc\/init\.d\/\(.*\) \(.*\)/service \2 \1/g'`
$EXEC

Next make the file executable, and then link it up.

chmod +x /usr/local/bin/service-reverser
ln -s /usr/local/bin/service-reverser /etc/init.d/start
ln -s /usr/local/bin/service-reverser /etc/init.d/stop
ln -s /usr/local/bin/service-reverser /etc/init.d/status
ln -s /usr/local/bin/service-reverser /etc/init.d/restart

Now you can reverse the argument and name when using service.

[[email protected] ~]# service status nginx
nginx (pid  17813) is running...
[[email protected] ~]# service nginx status
nginx (pid  17813) is running...

You may also like...

Leave a Reply

Your email address will not be published.