Linux creates self-start scripts

1. Go to the directory

cd /etc/init.d
Copy the code

2. Create script files

touch start-mongodb.sh
Copy the code

3. Write scripts

#! /bin/sh
# chkconfig: 345 99 10
# description: Auto-starts mongodb
echo "start mongodb"
cdBigdata/app/mongo - 4.0.2 / binCD Enter the specified directory
./mongod -f ../mongo.conf		#./mongod Execute the mongod. Sh script in the directory
Copy the code

3. Authorize, mount, and view

chmod +x /etc/init.d/start-mongodb.sh	Add execute permission

ln -s  /etc/init.d/start-mongodb /etc/rc2.d/S16mongodb		Run the mount command

chkconfig --add start-mongodb.sh		Add startTest to the list of system services

chkconfig start-mongodb.sh on		Set the On /off switch for startTest

chkconfig --list start-mongodb.sh   # check the registered start-mongodb service
Copy the code