Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does Shell operate to develop enterprise service startup scripts

2025-03-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces Shell how to operate and develop enterprise service startup scripts, the contents of the articles are carefully selected and edited by the author, with a certain pertinence, the reference significance for everyone is still relatively great, the following with the author to understand how to operate Shell to develop enterprise service startup scripts.

Description:

The MySQL startup command is:

/ bin/sh mysqld_safe-- pid-file=$mysqld_pid_file_path 2 > & 1 > / dev/null &

The stop command logic script is:

Mysqld_pid= `cat "$mysqld_pid_file_path" `if (kill-0 $mysqld_pid 2 > / dev/null) then kill $mysqld_pid sleep 2fi

Please complete the writing of the MySQL startup script, and realize that you can configure boot self-startup using chkconfig.

Requirements: implemented with functions, case statements, if statements, etc.

Answer: the technique of this question is suitable for most startup scripts, such as rsync,nginx, etc., only take MySQL as an example to introduce the idea.

Simple, easy to use, efficient and professional

#! / bin/bash# chkconfig: 2345 64 3mm description: MySQL startup# Author:oldboy# Blog: http://oldboy.blog.51cto.com# Time:2017-07-07 09Groupe 24 MySQL startup# Author:oldboy# Blog: Name:mysqld# Version:V1.0# Description:This is a test script. [- f / etc/init.d/functions] & & source / etc/init.d/functionsbindir= "/ application/mysql/bin" datadir= "/ application/mysql/data" mysqld_pid_file_path= "/ application/ Mysql/ `hostname`.pid "PATH=" / sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin "# this step is critical to boot and timing startup. Export PATHreturn_value=0# Lock directory.lockdir='/var/lock/subsys'lock_file_path= "$lockdir/mysql" log_success_msg () {echo "SUCCESS! $@" # pay attention to the indentation of the function, which is also a professional performance and can be put into functions. } log_failure_msg () {echo "ERROR! $@"} # Start Funcstart () {# Start daemon echo "Starting MySQL" if test-x $bindir/mysqld_safe # startup file is executable. Whether then $bindir/mysqld_safe-- datadir= "$datadir"-- pid-file= "$mysqld_pid_file_path" > / dev/null & return_value=$? # handles the return value is the key to distinguishing whether the script is professional or not. Whether the sleep 2 # Make lock for CentOS if test-w "$lockdir" # lock directory is writable. Then touch "$lock_file_path" # creates a lock file. Fi exit $return_value else log_failure_msg "Couldn't find MySQL server ($bindir/mysqld_safe)" fi} # Stop Funcstop () {if test-s "$mysqld_pid_file_path" # whether the PID file exists and the size is greater than 0. Then mysqld_pid= `cat "$mysqld_pid_file_path" `if (kill-0 $mysqld_pid 2 > / dev/null) # check whether the process corresponding to PID exists. Then echo "Shutting down MySQL" kill $mysqld_pid # cannot take-9, or you will suffer the consequences. Return_value=$? Sleep 2 else log_failure_msg "MySQL server process # $mysqld_pid is not running!" Rm-f "$mysqld_pid_file_path" fi # Delete lock for Oldboy's CentOS if test-f "$lock_file_path" then rm-f "$lock_file_path" fi exit $return_value else log_failure_msg "MySQL server PID file could not be found!" Fi} case "$1" in start) start;; stop) stop;; restart) if $0 stop; then $0 start else log_failure_msg "Failed to stop running server, so refusing to try to start." Exit 1 fi;; *) echo "Usage: $0 {start | stop | restart}" exit 1esacexit $return_value # whether to handle the return value is the key to distinguish whether the script is professional or not.

After reading the above about how Shell operates and develops enterprise service startup scripts, many readers must have some understanding. If you need more industry knowledge and information, you can continue to follow our industry information column.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report