宝兰德创建systemctl系统服务
|
1 2 3 |
## 启动/停止 中间件服务 ## BWS V3.1.0 操作用户: root 控制台停启脚本分别是: cd /home/bes/BWS310/bin; ./stopconsole 和 ./startconsole ## BWS V3.1.0 操作用户: root 实例已启动,实例停动脚本: cd /home/bes/BWS310/script; ./stopBWS.sh 和 ./startBWS.sh |
1. BWS 实例服务 bws.service
|
1 |
vim /etc/systemd/system/bws.service |
内容示例:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
[Unit] Description=BES BWS V3.1.0 Instance After=network.target [Service] Type=oneshot RemainAfterExit=yes User=root Group=root WorkingDirectory=/home/bes/BWS310/script ExecStart=/bin/bash /home/bes/BWS310/script/startBWS.sh ExecStop=/bin/bash /home/bes/BWS310/script/stopBWS.sh TimeoutStartSec=300 TimeoutStopSec=300 # oneshot 只能用 Restart=no,或直接删掉 Restart 行 Restart=no [Install] WantedBy=multi-user.target |
2. 控制台服务 bws-console.service(可选)
|
1 |
vim /etc/systemd/system/bws-console.service |
内容示例:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
[Unit] Description=BES BWS V3.1.0 Console After=network.target bws.service Wants=bws.service [Service] Type=oneshot RemainAfterExit=yes User=root Group=root WorkingDirectory=/home/bes/BWS310/bin ExecStart=/bin/bash /home/bes/BWS310/bin/startconsole ExecStop=/bin/bash /home/bes/BWS310/bin/stopconsole TimeoutStartSec=120 TimeoutStopSec=120 Restart=no [Install] WantedBy=multi-user.target |
3. 安装前必做检查
|
1 2 3 4 5 6 7 |
ls -l /home/bes/BWS310/script/startBWS.sh /home/bes/BWS310/script/stopBWS.sh ls -l /home/bes/BWS310/bin/startconsole /home/bes/BWS310/bin/stopconsole # 手动试一次(确认能启停) cd /home/bes/BWS310/script && ./startBWS.sh # 看进程、端口是否正常后再: cd /home/bes/BWS310/script && ./stopBWS.sh |
若脚本没有执行权限:
|
1 2 |
chmod +x /home/bes/BWS310/script/*.sh chmod +x /home/bes/BWS310/bin/startconsole /home/bes/BWS310/bin/stopconsole |
若脚本依赖当前目录下的相对路径,WorkingDirectory 必须和官方说明一致(上面已按你日志里的目录写好)。
4. 启用 systemd 服务
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
systemctl daemon-reload # 实例 systemctl enable bws.service systemctl start bws.service systemctl status bws.service systemctl stop bws.service systemctl is-enabled bws.service # 需要控制台时 systemctl enable bws-console.service systemctl start bws-console.service systemctl status bws-console.service systemctl stop bws-console.service systemctl is-enabled bws-console.service |
常用命令:
|
1 2 3 |
systemctl stop bws.service systemctl restart bws.service journalctl -u bws.service -f # 看启动日志 |
查看进程
|
1 |
netstat -ntlp |
