ubuntu-18.04 设置开机启动脚本
脚本设置流程及解析过程:
脚本设置流程:
ubuntu-18.04不能像ubuntu14一样通过编辑rc.local来设置开机启动脚本,通过下列简单设置后,可以使rc.local重新发挥作用。
建立rc-local.service文件
cat << RainyWang > /etc/systemd/system/rc-local.service[Unit]Description=/etc/rc.local CompatibilityConditionPathExists=/etc/rc.local[Service]Type=forkingExecStart=/etc/rc.local startTimeoutSec=0StandardOutput=ttyRemainAfterExit=yesSysVStartPriority=99[Install]WantedBy=multi-user.targetRainyWang
创建文件rc.local
cat << RainyWang > /etc/rc.local#!/bin/sh -e## rc.local## This script is executed at the end of each multiuser runlevel.# Make sure that the script will "exit 0" on success or any other# value on error.## In order to enable or disable this script just change the execution# bits.## By default this script does nothing./opt/mongodb/bin/mongod --config /etc/mongodb/co_adfs_primary.conf/opt/mongodb/bin/mongod --config /etc/mongodb/co_disktracker_primary.confRainyWang
给rc.local加上权限
chmod +x /etc/rc.local
启用服务
systemctl enable rc-local
启动服务并检查状态
systemctl start rc-local.servicesystemctl status rc-local.service
