linux_wiki:sysvinit_service_script

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
linux_wiki:sysvinit_service_script [2015/08/21 07:23]
billdozor [The Code]
linux_wiki:sysvinit_service_script [2015/10/01 23:00]
billdozor [The Code]
Line 24: Line 24:
 <code bash sysvinit-service> <code bash sysvinit-service>
 #!/bin/sh #!/bin/sh
-SysV-Init: Generic sysvinit script+Title: Generic sysvinit script
 # Description: General service script to control a process with sysvinit # Description: General service script to control a process with sysvinit
 # Check Config => Starts on run levels 2,3,4,5. Start Priority => 80, Stop Priority => 20 # Check Config => Starts on run levels 2,3,4,5. Start Priority => 80, Stop Priority => 20
 # chkconfig: 2345 80 20 # chkconfig: 2345 80 20
-# 
  
-## Application Variables - Customize Here ##+#### Application Variables - Customize Here ####
 # The service name # The service name
 prog=service-name prog=service-name
Line 40: Line 39:
 # Directory the program is located in and the start script name # Directory the program is located in and the start script name
 prog_root=/home/${prog_user} prog_root=/home/${prog_user}
-prog_script=run-progname.sh+prog_script=run-program-name.sh
  
 # Location of config file and startup log file # Location of config file and startup log file
Line 51: Line 50:
 # How long to give the program to startup (in seconds),before checking status # How long to give the program to startup (in seconds),before checking status
 prog_sleep=10 prog_sleep=10
-## End of Application Variables ##+#### End of Application Variables #### 
 + 
 +# Use init.d functions for echo status 
 +source /etc/init.d/functions
  
 check_required() { check_required() {
Line 58: Line 60:
    continue    continue
  else  else
-   echo "Error: Must have root privileges or be the ${prog_user} user."+   echo -e "Error: Must have root privileges or be the ${prog_user} user.\c" 
 +          echo_failure
    exit 4    exit 4
  fi  fi
Line 66: Line 69:
    continue    continue
  else  else
-   echo "Error: ${prog_root}/${prog_script} is not executable or does not exist."+   echo -e "Error: ${prog_root}/${prog_start} is not executable or does not exist.\c" 
 +          echo_failure
    exit 5    exit 5
  fi  fi
Line 80: Line 84:
         # If config file is missing, exit with error         # If config file is missing, exit with error
  if [[ ! -f ${prog_config} ]];then  if [[ ! -f ${prog_config} ]];then
-   echo "Error: config file, ${prog_config}, not found!"+   echo -e "Error: config file, ${prog_config}, not found!\c" 
 +          echo_failure 
 +          echo
    exit 6    exit 6
  fi  fi
Line 87: Line 93:
  check_isrunning  check_isrunning
  if [[ ${isrunning} == "0" ]];then  if [[ ${isrunning} == "0" ]];then
-   echo "${prog} is already running."+   echo -e "${prog} is already running.\c" 
 +          echo_passed 
 +          echo
    exit 0    exit 0
  else  else
Line 114: Line 122:
    sleep 5    sleep 5
  else   else
-   echo "Nothing to stop...${prog} is not running."+   echo -e "Nothing to stop...${prog} is not running.\c" 
 +          echo_passed 
 +          echo
    exit 0    exit 0
  fi  fi
Line 129: Line 139:
  if [[ ${isrunning} == "0" ]];then  if [[ ${isrunning} == "0" ]];then
    process_count=$(pgrep -l -u ${prog_user} -f ${pgrep_pattern} | wc -l)    process_count=$(pgrep -l -u ${prog_user} -f ${pgrep_pattern} | wc -l)
-   echo "${prog} is running...found ${process_count} occurence(s)."+   echo -e "${prog} is running...found ${process_count} occurence(s).\c" 
 +          echo_success 
 +          echo
    echo "PID  COMMAND"    echo "PID  COMMAND"
    pgrep -l -u ${prog_user} -f ${pgrep_pattern}    pgrep -l -u ${prog_user} -f ${pgrep_pattern}
    exit 0    exit 0
  else  else
-   echo "${prog} is not running."+   echo -e "${prog} is not running.\c" 
 +          echo_failure 
 +          echo
    exit 1    exit 1
  fi  fi
  • linux_wiki/sysvinit_service_script.txt
  • Last modified: 2019/05/25 23:50
  • (external edit)