viernes, 30 de abril de 2010
Generic script for managing a Unix service
Create a file with the following contents:
#!/bin/bash
export user_name="root" 
export srv_name="serv"
export  exec_dir_stop="/home/$user_name/bin/stop_serv.sh"
export  exec_dir_start="/home/$user_name/bin/start_serv.sh" 
case "$1" in
    start)
        echo -n  "Starting $srv_name Service Daemon" 
        /usr/bin/sudo -u $user_name  $exec_dir_start
        ;;
    stop)
        echo -n "Shutting $srv_name Service Daemon"
        /usr/bin/sudo -u $user_name $exec_dir_stop 
        ;;
    restart)
        $0 stop
        $0 start 
        ;;
    *)
        echo "Usage: $0 {start|stop|restart}" 
        exit 1
        ;;
esac 
Save it with a descriptive name on /etc/init.d (or /etc/rc.d) , for instance http_filter . Change the access rights to the user in charge of managing the service, and create a softlink on the run level you want the service to be started.
 
