Tag cloud

JBoss (16) Fedora (5) Linux (4) Red Hat (4) JON (3) command line (3) 4.3 (2) JEE (2) JVM (2) Java (2) KVM (2) Oracle (2) Portal (2) Weblogic (2) installation (2) vs (2) /boot partition (1) Add-ons (1) Apache (1) Bundles (1) Business model (1) Byteman (1) CLASSPATH (1) EAP (1) EPP (1) Eclipse (1) Failover (1) Gnome (1) JAVA_OPTS (1) JBDS (1) JBoss Tools (1) JBossON (1) JConsole (1) JDK (1) JMS (1) JVM options (1) KDE (1) MBean (1) Network (1) Open Source (1) RHQ (1) Red Hat subscription (1) Thunderbird (1) Troubleshooting (1) Virtulization (1) WS (1) Webservices (1) Wireshark (1) classloading (1) clustering (1) comparison (1) debug (1) deployment (1) disable SELinux (1) disksize (1) error (1) fun (1) jboss.org (1) log (1) log4j (1) lvm (1) messaging (1) multiple WARs (1) patent FOSS (1) performance tuning (1) provisionning (1) scripting (1) services (1) switch (1) troll (1) upgrade (1) video (1) war (1) webapp (1) yum (1)

29 August 2010

Writing start scripts for services in Fedora linux

Howto manage your services and programs within Fedora

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 &

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

No comments:

Post a Comment