Ir al contenido
  • +31 653-919-302
Cafayate.Net
  • 0
  • 0
  • Inicia sesión
  • Nederlands English (US) Español (AR)
  • Contáctanos
  • Inicio
  • Blog
  • Empleos
  • Contáctanos
Cafayate.Net
  • 0
  • 0
    • Inicio
    • Blog
    • Empleos
    • Contáctanos
  • +31 653-919-302
  • Nederlands English (US) Español (AR)
  • Inicia sesión
  • Contáctanos

Creating an Init Script in Ubuntu 14.04

  • Todos los blogs
  • Tech Blog
  • Creating an Init Script in Ubuntu 14.04
  • 5 de marzo de 2021 por
    Administrator

    In Ubuntu, you create init scripts using the SysV init system. Details are here. In this article, I will create a very simple script to start and stop Tomcat.

    In this tutorial, our goal is to start and stop Tomcat as the user “joe”. First, we will create a script called tomcat in /etc/init.d folder.

    #! /bin/sh
    ### BEGIN INIT INFO
    # Provides: tomcat
    # Required-Start: $remote_fs $syslog
    # Required-Stop: $remote_fs $syslog
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: Tomcat
    # Description: This file starts and stops Tomcat server
    # 
    ### END INIT INFO
    
    TOMCAT_DIR=/home/joe/programs/apache-tomcat-8.0.5/
    export JAVA_HOME=/home/joe/programs/jdk1.8.0_05
    
    case "$1" in
     start)
       su joe -c $TOMCAT_DIR/bin/startup.sh
       ;;
     stop)
       su joe -c $TOMCAT_DIR/bin/shutdown.sh
       sleep 10
       ;;
     restart)
       su joe -c $TOMCAT_DIR/bin/shutdown.sh
       sleep 20
       su joe -c $TOMCAT_DIR/bin/startup.sh
       ;;
     *)
       echo "Usage: tomcat {start|stop|restart}" >&2
       exit 3
       ;;
    esac

    The “Default-Start” field specifies the run levels in which the script will be run with the “start” argument. “Default-Stop” does the reverse. For example, when the machines shuts down and enters run level 1, the script will be run with the “stop” argument.

    Make the script executable:

    sudo chmod a+x tomcat

    Always unit test the script by running it from the command line. For example:

    sudo ./tomcat start
    sudo ./tomcat stop

    If all goes well then register the script as an init script:

    sudo update-rc.d tomcat defaults

    Reboot the machine and make sure that Tomcat has started.

    en Tech Blog
    Automated WordPress installation with Ansible

    Diseñado para empresas

    Somos un equipo de personas apasionadas cuyo objetivo es mejorar la vida de todos a través de productos revolucionarios. Creamos grandes productos para resolver sus problemas empresariales. Nuestros productos están diseñados para pequeñas y medianas empresas dispuestas a optimizar su rendimiento.

    Contáctenos

    Plantexel
    Pedernera
    Salta Capital 
    Argenina

    • +31 653-919-302
    • [email protected]
    Síganos
    Copyright © Plantexel
    Nederlands | English (US) | Español (AR)