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 Compatibility
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
RainyWang
创建文件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.conf
RainyWang
给rc.local加上权限
chmod +x /etc/rc.local
启用服务
systemctl enable rc-local
启动服务并检查状态
systemctl start rc-local.service
systemctl status rc-local.service