Linux Service Mode Launcher script (INIT.D script)

Source: Internet
Author: User

This is really the correct script to get the jar background started, the various Nohoup scripts on the network are used to perform a task on a temporary basis.

#!/bin/sh## init.d script ##### BEGIN init info# provides:mongodb# required-start: $network $local _fs $remote _fs# required-stop: $network $local _fs $remote _fs# should-start: $named # should-stop:# default-start:2 3 4 5 # default-stop:0 1 6# short-description:an object/document-oriented database# Description:mongodb is a high-                    Performance, open source, schema-free# document-oriented data store that's easy to deploy, manage# and use.                       It ' s network accessible, written in C + + and offers# the following features:#. #                       * Collection oriented storage-easy storage of object-# style data#                       * Full index support, including on inner objects# * Query profiling#         * Replication and Fail-over support# * Efficient storage of binary data including large#                Objects (e.g. videos) # * auto-sharding for Cloud-level Scalability (Q209) #                    . # This is the build with V8 JavaScript engine.#. # High performance, scalability, and reasonable depth of# functionality is the goals for the project.## # END INIT infodaemon=/usr/local/jdk1.8.0_40/bin/javaoption=-jarvar=/usr/local/danabang.storage/  danabang.storage.jardesc=danabang.storage# Default defaults. Can be overridden by the/etc/default/$NAMENAME =danabang.storagepidfile=/var/data/danabang.storage/log/$ NAME.PIDRUNAS=TANGRUIIF Test! -X $DAEMON; Then echo "Could not find $DAEMON" exit 0fi.                            /LIB/LSB/INIT-FUNCTIONSSTARTTIME=1DIETIME=10 # Time to wait for the server to die, in seconds # If This value was set too low might not # Let some servers to die Gracefu                           Lly and # ' Restart ' would not workrunning_pid () {# Check If a given process PID ' s cmdline matches a given name pid=$1 name=$ 2 [-Z "$pid"] && return 1 [!-d/proc/$pid] && return 1 cmd= ' cat/proc/$pid/cmdline |    TR "\000" "\ n" |head-n 1 |cut-d:-F 1 ' # is this expected server ["$cmd"! = "$name"] && return 1 Return 0}running () {# Check If the process is running looking at/proc# (works for all users) # No Pidfile, probably n o Daemon Present [!-F "$PIDFILE"] && return 1 pid= ' cat $PIDFILE ' running_pid $pid $DAEMON | | Return 1 return 0}start_server () {# Start the process using the wrapper Start-stop-daemon--background--sta  RT--quiet--pidfile $PIDFILE--make-pidfile--chuid $RUNAS--exec $DAEMON --$OPTION $VAR errcode=$?return $errcode}stop_server () {# Stop the process using the wrapper start -stop-daemon--stop--quiet--pidfile $Pidfile--user $RUNAS--exec $DAEMON Errcode=$?return $errcode}  Force_stop () {# force the process-to-die killing it manually[!-e "$PIDFILE"] && returnif running; thenkill-15 $pid # Is it really dead?sleep "$DIETIME" SIF running; Thenkill-9 $pidsleep "$DIETIME" SIF running; Thenecho "Cannot kill $NAME (pid= $pid)!" Exit 1fififirm-f $PIDFILE}case "$" in start) log_daemon_msg "Starting $DESC" "$NAME" # Check if it ' s running Firs  t if running;        Then log_progress_msg "apparently already running" Log_end_msg 0 Exit 0 fi if Start_server; Then # Note:some servers might die Some time after they start, # This code would detect this issue I F STARTTIME is set # to a reasonable value [-n "$STARTTIME"] && sleep $STARTTIME # Wait so  Me time if running; Then # It's OK, the server started anD is running log_end_msg 0 Else # It's not running after we do start Log_end_msg 1 fi Else # either we could not start it log_end_msg 1 fi;  ; Stop) log_daemon_msg "stopping $DESC" "$NAME" if running; Then # only stop the server if we see it runningerrcode=0 Stop_server | |            Errcode=$? Log_end_msg $errcode Else # If It's not running don ' t anything log_progress_msg "apparentl  Y not running "Log_end_msg 0 exit 0 fi; force-stop) # First try to stop gracefully the program $ stop if running; Then # If It's still running try to kill it more forcefully log_daemon_msg "stopping (force) $DESC" "$NAME" Errcode=0 force_stop | |            Errcode=$?  Log_end_msg $errcode fi;; Restart|force-reload) log_daemon_msg "REstarting $DESC "$NAME" Errcode=0 Stop_server | |        Errcode=$? # Wait Some sensible amount, some server need this [-n "$DIETIME"] && sleep $DIETIME start_server ||        Errcode=$? [-N "$STARTTIME"] && sleep $STARTTIME Running | |        Errcode=$?  Log_end_msg $errcode;;  Status) log_daemon_msg "Checking Status of $DESC" "$NAME" if running; Then log_progress_msg "Running" log_end_msg 0 else log_progress_msg "apparently no  T running "Log_end_msg 1 exit 1 fi; *) n=/etc/init.d/$NAMEecho "Usage: $N {start|stop|force-stop|restart|force-reload|status}" >&2exit 1;; Esacexit 0

Linux Service Mode Launcher script (INIT.D script)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.