Under the Linux system, how to set the nacos program to start with the specified user on the machine?

1. Create a startup file in the /etc/init.d/ directory, for example: nacosd

2. Configure sudo environment variables

# vi /etc/sudoers

Add the following line:

Defaults    env_keep += "JAVA_HOME PATH"

3. Write the content of the startup file nacosd, as follows:

#!/bin/sh
### BEGIN INIT INFO
# Provides:     nacos
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    nacos  server
# Description:          nacos  server.
### END INIT INFO

# When using sudo, enable global environment variables, JAVA_HOME and PATH are set in /etc/profile (slightly)
source /etc/profile

EXEC=/usr/local/nacos/bin

# 已tomcat用户启动nacos服务
USER_EXE="sudo -u tomcat bash -c "
case "$1" in
    start)
        echo "Starting nacos  server..."
        $USER_EXE "$EXEC/startup.sh -m standalone"
        ;;
    stop)
        echo "Stopping nacos  server..."
        $USER_EXE "$EXEC/shutdown.sh"
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac

4. Add startup items
# chkconfig --add nacosd

5. Set the startup sequence
# chkconfig --level 41 nacosd on

6. Start the service
# service nacosd start

7. Stop the service
# service nacosd stop
 

Guess you like

Origin blog.csdn.net/songchaofly/article/details/107664004