1. Make your shell script executable
All shell scripts in /usr/bin/ or /sbin/ can be executed anywhere within the command line
Add a softlink into /sbin or /usr/bin
$ cd /sbin
$ ln -s /app/jon/bin/rhq-server.sh jon
$ jon
1.5. Start your shell script at startup by modifying
Example:
$ sudo vi /etc/rc.d/rc.local
add:
killall -9 knetworkmanager & qdbus org.kde.kded /kded unloadModule networkmanagement && nm-applet &
killall -9 knetworkmanager & qdbus org.kde.kded /kded unloadModule networkmanagement && nm-applet &
2. Start your program easily via shell script
If you have a shell that takes the standard arguments : start / stop / restart
you can it into the repository /etc/init.d/.
All scripts in /etc/init.d/ can be called with
$ service my_script start
For convenience use a softlink instead of copying it into /etc/init.d:
$ cd /etc/init.d
$ ln -s /app/jon/bin/rhq-server.sh jon
$ service jon start
3. Service registry within Fedora (the startup services)
List all available services (/etc/init.d)
$ chkconfig --list
Start / stop the ssh daemon service
$ chkconfig sshd start (or stop)
Enable a service
$ chkconfig --add ssh
$ chkconfig sshd on
Disable a service
$ chkconfig sshd off
$ chkconfig sshd --del
If you you prefer a graphical interface for the service registry use
$ system-config-services
4. Making an executable 'servicable'
Create a file in /etc/init.d, here an example: shutter
#!/bin/sh
#
# shutter This script starts and stops the shutter daemon
#
# chkconfig: - 78 30
# processname: shutter
# description: shutter is a daemon process
get_shutter_pid () {
SHUTTERPID=$( ps aux --cols 1024 | grep "perl" | grep "/usr/bin/shutter" | awk '{ print $2 }' | head -n 1 )
}
PIDFILE=/var/run/shutter.pid
# By default it's all good
RETVAL=0
BASE="/usr/bin"
# See how we were called.
case "$1" in
start)
# Start daemon.
echo -n $"Starting shutter: "
export DISPLAY=:0
nohup ${BASE}/shutter > /dev/null &
sleep 1
get_shutter_pid
echo -n ${SHUTTERPID} > ${PIDFILE}
echo "Start Shutter : pid = ${SHUTTERPID}"
;;
stop)
# Stop daemons.
get_shutter_pid
if ! [ -z "${SHUTTERPID}" ] ; then
echo "Stop Shutter : pid = ${SHUTTERPID}"
kill "${SHUTTERPID}"
fi
;;
restart|force-reload)
$0 stop
sleep 8
$0 start
;;
status)
get_shutter_pid
if [ -z "${SHUTTERPID}" ] ; then
echo "Shutter is stopped"
exit 1
else
echo "Shutter (pid ${SHUTTERPID}) is being executed..."
exit 0
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
RETVAL=1
;;
esac
exit $RETVAL
#!/bin/sh
#
# shutter This script starts and stops the shutter daemon
#
# chkconfig: - 78 30
# processname: shutter
# description: shutter is a daemon process
get_shutter_pid () {
SHUTTERPID=$( ps aux --cols 1024 | grep "perl" | grep "/usr/bin/shutter" | awk '{ print $2 }' | head -n 1 )
}
PIDFILE=/var/run/shutter.pid
# By default it's all good
RETVAL=0
BASE="/usr/bin"
# See how we were called.
case "$1" in
start)
# Start daemon.
echo -n $"Starting shutter: "
export DISPLAY=:0
nohup ${BASE}/shutter > /dev/null &
sleep 1
get_shutter_pid
echo -n ${SHUTTERPID} > ${PIDFILE}
echo "Start Shutter : pid = ${SHUTTERPID}"
;;
stop)
# Stop daemons.
get_shutter_pid
if ! [ -z "${SHUTTERPID}" ] ; then
echo "Stop Shutter : pid = ${SHUTTERPID}"
kill "${SHUTTERPID}"
fi
;;
restart|force-reload)
$0 stop
sleep 8
$0 start
;;
status)
get_shutter_pid
if [ -z "${SHUTTERPID}" ] ; then
echo "Shutter is stopped"
exit 1
else
echo "Shutter (pid ${SHUTTERPID}) is being executed..."
exit 0
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
RETVAL=1
;;
esac
exit $RETVAL
No comments:
Post a Comment