This topic describes how to configure an OBServer node to start automatically on boot through online settings or offline settings depending on whether the OBServer node can access the Internet.
Note
You must separately configure the automatic start settings for each OBServer node in an OceanBase cluster.
Scenarios
The configuration methods described in this topic are applicable only if the following requirements are met:
An OceanBase cluster is deployed and not managed by OceanBase Shell (OBShell).
You are using OceanBase Database V4.2.1.4 or later.
Online settings
If an OBServer node can access Internet, you can log on to the OBServer node and run the following command:
[admin@test001 ~]$ sudo bash -c "$(curl -s https://obbusiness-private.oss-cn-shanghai.aliyuncs.com/download-center/opensource/obshell/service_installer.sh)"
Offline settings
If an OBServer node cannot access the Internet, you can log on to the OBServer node and perform the following operations:
Create a script file.
In this example, the file is named
self_start.sh. You can use a custom name as needed.[admin@test001 ~]$ vim self_start.shThe content of the script file is as follows:
#!/bin/bash # Prompt the user for input and retrieve it prompt_for_input() { local prompt_message="$1" local user_input read -p "$prompt_message" user_input echo "$user_input" } # Check if the homepath argument was provided via the command line expected_arg_name="homepath" if [ $# -gt 0 ]; then arg_value="$1" else # No arguments provided, ask the user for the homepath arg_value=$(prompt_for_input "Please enter the $expected_arg_name: ") fi echo "Using $expected_arg_name: $arg_value" # Check for the existence of the 'obshell' file in the provided homepath homepath=$arg_value obshell="$homepath/bin/obshell" if [ ! -f "$obshell" ]; then echo -e "\033[31m[ERROR]\033[0m Sorry, [$obshell] does not exist." echo "You may need to upgrade the obcluster. Please consult the developers for assistance." exit 1 else echo "[$obshell] has been found in the work directory." fi # Check if the oceanbase.service file exists system_dir="/etc/systemd/system" oceanbase=$system_dir/oceanbase.service # Check if the service file exists if [ -f "$oceanbase" ]; then echo -e "\033[33m[WARN]\033[0m oceanbase.service has beed installed." echo "Please use 'systemctl status oceanbase.service' to check it." exit 0 else echo "Service file $oceanbase does not exist." fi # Retrieve the owner of the 'observer' process configuration files owner=$(stat -c '%U' $homepath/etc) echo "Owner of the observer configuration: $owner" # Construct and output the content for the systemd service unit file name=observer.service mkdir -p $homepath/tmp file=$homepath/tmp/$name echo "Creating the service unit file at $file..." # Write the service content to the file cat << EOF > ${file} [Unit] Description=observer After=network.target [Service] User=${owner} Type=forking KillSignal=SIGKILL ExecStartPre=${homepath}/bin/obshell admin stop ExecStart=${homepath}/bin/obshell admin start --takeover 0 ExecStartPost=${homepath}/bin/obshell admin stop ExecStop=${homepath}/bin/obshell admin stop PIDFile=${homepath}/run/observer.pid Restart=no SuccessExitStatus=SIGKILL [Install] WantedBy=multi-user.target EOF echo "The content of the Service unit file is:" sed 's/^/ /' "$file" # Deploy the unit configuration file to the system directory echo "Deploying the service unit file to the system directory" cp -f $file $system_dir/$name echo "Updating permissions for the service unit file..." chmod 644 $system_dir/$name echo "Reloading the systemd daemon to recognize the new service" systemctl daemon-reload systemctl enable observer.service echo -e "\033[32m[SUCCEED]\033[0m observer.service has been installed."Run the script file.
In this example,
/home/admin/oceanbaseis the installation directory of the OceanBase cluster. Specify the actual directory when you run the script file.[admin@test001 ~]$ sudo sh self_start.sh /home/admin/oceanbase