我的操作系统是 Centos 7,我使用 systemd 创建了一个服务来运行我的 mongodb 数据库,我在“/usr/lib/systemd/system/”下创建了该服务,我将其命名为“mongo.service”
当我使用
启动服务时sudo systemctl start mongo.service
没有显示错误,但看不到mongodb在指定端口27017上监听,这意味着它最终没有启动。
当我使用脚本启动数据库时:
sudo /usr/local/iot/mongodb-linux-x86_64-3.0.5/start_mongod.sh
数据库开始监听。
这是 mongo.service 包含的内容
[Unit]
Description= mongo db data base
[Service]
Type=oneshot
RemainAfterExit=no
ExecStart=/usr/local/iot/mongodb-linux-x86_64-3.0.5/start_mongod.sh
[Install]
WantedBy=multi-user.target
这是我的脚本 start_mongod.sh 包含的内容:
#!/bin/bash
/usr/local/iot/mongodb-linux-x86_64-3.0.5/bin/mongod --dbpath /usr/local/iot/mongodb-linux-x86_64-3.0.5/data/db --port 27017 --smallfiles --logpath /usr/local/iot/mongodb-linux-x86_64-3.0.5/log/mongoc.log --pidfilepath /usr/local/iot/mongodb-linux-x86_64-3.0.5/log/mongod.pid --logappend &
为了能够将我的 mongo db 作为服务启动,我错过了什么? 预先感谢您的帮助!
最佳答案
关于linux - centos7 : create service to start script bash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31916516/