Create systemd service and start it in one bash script.
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
SERVICE=mongosqld
EXECUTABLE=/usr/bin/mongosqld
ARGS=/data/mongosqld/mongosqld.conf
sudo sh -c "cat > /usr/lib/systemd/system/${SERVICE}.service <<EOF
[Unit]
Description=${SERVICE} service
[Service]
Type=simple
User=${USER}
WorkingDirectory=/home/${USER}
ExecStart=${EXECUTABLE} ${ARGS}
Restart=always
RestartSec=1
[Install]
WantedBy=multi-user.target
EOF"
sudo systemctl enable ${SERVICE}
sudo systemctl start ${SERVICE}
sudo systemctl status ${SERVICE}
最新评论