在RHEL7/CENTOS7/SUSE12及最新的Ubuntu等linux发行版本中, 均使用systemd进行服务控制管理(Service Control Manager)。
使用systemd, 不再需要编写shell脚本程序来控制启动、关闭。
以下是通过systemd方式实现GBase 8s数据库的自启动与关闭。
适用于操作系统: RHEL7/CENTOS7, 以及基于RHEL7内核的系统
###systemd需要的两个配置文件目录为
1,service 文件所在位置(CentOS7/RHEL7)
/usr/lib/systemd/system/
Ubuntu系统中为:
/lib/systemd/system/
2,service 的环境配置文件位置(CentOS7/RHEL7)
/etc/sysconfig/
Ubuntu系统中默认为/etc
/etc/
1, 在/usr/lib/systemd/system/目录下创建 gbasedbtd.service文件
[Unit]
Description=GBase 8s Database Server v8.7 2.0.1a2_2
Documentation=file:/opt/gbase/release/en_us/0333
Wants=network-online.target
After=network.target network-online.target
[Service]
Type=oneshot
User=gbasedbt
Group=gbasedbt
RemainAfterExit=yes
EnvironmentFile=/etc/sysconfig/gbasedbtd_service
ExecStart=/opt/gbase/bin/oninit
ExecStop=/opt/gbase/bin/onmode -ky
#Restart=on-abort
[Install]
WantedBy=multi-user.target
说明:
[Unit] 区块:启动顺序与依赖关系
[Service] 区块:启动行为
[Install] 区块:定义如何安装这个配置文件,即怎么做到开机启动。
2, 在/etc/sysconfig目录下创建 gbasedbtd_service
# gbasedbtd.service environmental variables
GBASEDBTDIR=/opt/gbase
GBASEDBTSERVER=gbase01
ONCONFIG=onconfig.gbase01
GBASEDBTSQLHOSTS=/opt/gbase/etc/sqlhosts
3, 管理gbasedbtd服务
启动gbasedbtd服务(数据库应未启动)
# systemctl start gbasedbtd
检查gbasedbtd状态
# systemctl status gbasedbtd
关闭gbasedbtd服务
# systemctl stop gbasedbtd
设置gbasedbtd服务随系统启动
# systemctl enable gbasedbtd
关闭gbasedbtd服务的自启动
# systemctl disable gbasedbtd