描述:

linux7安装oracle11G后,设置开机自启动

问题:

当服务器重启或使用systemctl start oracle.service以后,会把在start的脚本执行,并把stop的脚本一起执行。

配置文件和脚本:

[root@localhostray]#vim/lib/systemd/system/oracle.service[Unit]Description=oracleServerAfter=network.target[Service]Type=forkingExecStart=/root/scripts/dbstart.shExecStop=/root/scripts/dbstop.shExecReload=PrivateTmp=true[Install]WantedBy=multi-user.target[root@localhostscripts]#vimdbstart.sh#!/bin/bashsu-oracle-c"dbstart"[root@localhostscripts]#vimdbstop.sh#!/bin/bashsu-oracle-c"dbshut"


解决:

不使用脚本调用oracle用户的命令,而是直接指定服务的用户和属组。

[root@localhostray]#vim/lib/systemd/system/oracle.service[Unit]Description=oracleServerAfter=network.target[Service]Type=forkingUser=oracleGroup=oinstallExecStart=/u01/oracle/product/11.2.0/db_1/bin/dbstartExecStop=/u01/oracle/product/11.2.0/db_1/bin/dbshutExecReload=PrivateTmp=true[Install]WantedBy=multi-user.target