Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
linux_wiki:sysvinit_service_script [2015/08/21 07:23] billdozor [The Code] |
linux_wiki:sysvinit_service_script [2019/05/25 23:50] (current) |
||
---|---|---|---|
Line 6: | Line 6: | ||
**Checklist** | **Checklist** | ||
- | * Linux distro with SysVInit init system. | + | * Distro(s): Enterprise |
---- | ---- | ||
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: | # Description: | ||
# 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=/ | prog_root=/ | ||
- | 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), | # How long to give the program to startup (in seconds), | ||
prog_sleep=10 | prog_sleep=10 | ||
- | ## End of Application Variables ## | + | #### End of Application Variables #### |
+ | |||
+ | # Use init.d functions for echo status | ||
+ | source / | ||
check_required() { | check_required() { | ||
Line 58: | Line 60: | ||
continue | continue | ||
else | else | ||
- | echo " | + | echo -e " |
+ | echo_failure | ||
exit 4 | exit 4 | ||
fi | fi | ||
Line 66: | Line 69: | ||
continue | continue | ||
else | else | ||
- | echo " | + | echo -e " |
+ | 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 " | + | echo -e " |
+ | echo_failure | ||
+ | echo | ||
exit 6 | exit 6 | ||
fi | fi | ||
Line 87: | Line 93: | ||
check_isrunning | check_isrunning | ||
if [[ ${isrunning} == " | if [[ ${isrunning} == " | ||
- | echo " | + | echo -e " |
+ | echo_passed | ||
+ | echo | ||
exit 0 | exit 0 | ||
else | else | ||
Line 114: | Line 122: | ||
sleep 5 | sleep 5 | ||
else | else | ||
- | echo " | + | echo -e " |
+ | echo_passed | ||
+ | echo | ||
exit 0 | exit 0 | ||
fi | fi | ||
Line 129: | Line 139: | ||
if [[ ${isrunning} == " | if [[ ${isrunning} == " | ||
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 " | + | echo -e " |
+ | echo_success | ||
+ | echo | ||
echo " | echo " | ||
pgrep -l -u ${prog_user} -f ${pgrep_pattern} | pgrep -l -u ${prog_user} -f ${pgrep_pattern} | ||
exit 0 | exit 0 | ||
else | else | ||
- | echo " | + | echo -e " |
+ | echo_failure | ||
+ | echo | ||
exit 1 | exit 1 | ||
fi | fi |