GBase8c 500[单机版]开机自启动
添加systemd服务方式
1、编辑服务
[root@keep-gbase8c-stand ~]# vim /usr/lib/systemd/system/gbase8c.service
# 定义单元
[Unit]
# 服务的描述信息,说明该服务是GBase8c数据库服务器
Description=GBase8c Database Server
# 在syslog和network目标之后启动
After=syslog.target network.target
# 定义服务
[Service]
# 服务类型为forking,表示服务将在启动时派生一个子进程,后台运行
Type=forking
# 以gbase用户身份运行服务
User=gbase
# 以gbase用户组身份运行服务
Group=gbase
# .bashrc 环境变量可以查看
# 设置GPHOME环境变量为GBase8c的安装路径
Environment=GPHOME=/dbdata/gbase/install/om
# 设置PGDATA环境变量为GBase8c数据目录路径
Environment=PGDATA=/dbdata/gbase/install/data
# 设置GAUSSHOME环境变量为GBase8c的程序路径
Environment=GAUSSHOME=/dbdata/gbase/install/app
# Exec 必须是绝对路径
# 启动服务的命令
ExecStart=/dbdata/gbase/install/om/venv/bin/python3 /dbdata/gbase/install/om/script/gs_om -t start
# 停止服务的命令
ExecStop=/dbdata/gbase/install/om/venv/bin/python3 /dbdata/gbase/install/om/script/gs_om -t stop
# 重新加载服务的命令
ExecReload=/dbdata/gbase/install/om/venv/bin/python3 /dbdata/gbase/install/om/script/gs_om -t restart
KillMode=mixed
KillSignal=SIGINT
TimeoutSec=0
# 配置服务的安装属性
[Install]
# 系统运行在多用户模式下
WantedBy=multi-user.target
2、重新加载服务配置
[root@keep-gbase8c-stand ~]# systemctl daemon-reload
3、测试服务
[root@keep-gbase8c-stand ~]# systemctl start gbase8c.service
[root@keep-gbase8c-stand ~]# systemctl stop gbase8c.service
[root@keep-gbase8c-stand ~]# systemctl enable gbase8c.service
注意:
以下报错为环境变量问题,调用了系统的python3
[root@keep-gbase8c-stand ~]# tail -f /var/log/messages
Jun 4 15:39:01 keep-gbase8c-stand systemd: Created slice User Slice of barman.
Jun 4 15:39:01 keep-gbase8c-stand systemd: Started Session 287 of user barman.
Jun 4 15:39:02 keep-gbase8c-stand systemd: Removed slice User Slice of barman.
Jun 4 15:39:46 keep-gbase8c-stand systemd: Starting GBase8c Database Server...
Jun 4 15:39:49 keep-gbase8c-stand gs_om: Failed to execute cmd: rm -rf '/dbdata/gbase/install/om/script/gspylib/common/./../../../lib/psutil/_psutil_linux.so' && cp -r '/dbdata/gbase/install/om/script/gspylib/common/./../../../lib/psutil/_psutil_linux.so_3.6' '/dbdata/gbase/install/om/script/gspylib/common/./../../../lib/psutil/_psutil_linux.so' && rm -rf '/dbdata/gbase/install/om/script/gspylib/common/./../../../lib/psutil/_psutil_posix.so' && cp -r '/dbdata/gbase/install/om/script/gspylib/common/./../../../lib/psutil/_psutil_posix.so_3.6' '/dbdata/gbase/install/om/script/gspylib/common/./../../../lib/psutil/_psutil_posix.so' . Error:
Jun 4 15:39:49 keep-gbase8c-stand gs_om: cp: 无法获取"/dbdata/gbase/install/om/script/gspylib/common/./../../../lib/psutil/_psutil_linux.so_3.6" 的文件状态(stat): 没有那个文件或目录
Jun 4 15:39:49 keep-gbase8c-stand systemd: gbase8c.service: control process exited, code=exited status=1
Jun 4 15:39:49 keep-gbase8c-stand systemd: Failed to start GBase8c Database Server.
Jun 4 15:39:49 keep-gbase8c-stand systemd: Unit gbase8c.service entered failed state.
Jun 4 15:39:49 keep-gbase8c-stand systemd: gbase8c.service failed.
Jun 4 15:40:01 keep-gbase8c-stand systemd: Created slice User Slice of barman.
Jun 4 15:40:01 keep-gbase8c-stand systemd: Started Session 288 of user barman.
Jun 4 15:40:01 keep-gbase8c-stand systemd: Removed slice User Slice of barman.