- centos7下使用systemd作为系统服务
- 创建服务项的方法:
- 创建文件/etc/systemd/system/xxx.service
- 文件内容如下:
[Unit]
Description=OrientDB Standalone Server
After=network.target
After=syslog.target[Install]
WantedBy=multi-user.target[Service]
User=graph
Group=graph
Type=simple
EnvironmentFile=/home/graph/orientdb-enterprise-2.2.31/bin/orientdb-env
ExecStart=/home/graph/orientdb-enterprise-2.2.31/bin/server.sh
注意项: Type 根据对应的ExecStart脚本的类型来确定,simple或者forking, 如果脚本即为主进程,不会退出,那就是simple; 如果脚本会启动另外的新进程,完成后脚本会自动退出,就选forking
systemd不会自动执行~/.bashrc, 所以需要的环境变量需要指定一个环境变量的文件,即EnvironmentFile所指向的那个文件,环境变量在里面指定; 文件内容直接写 JAVA_HOME=/home/xxx- systemctl enable xxx.service
- 启动 systemctl start xxx
- 停止 systemctl stop xxx