to be
a problem slover

systemd bash script

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}
赞(25) 打赏
欢迎转载,注明出处:刘世明的博客 » systemd bash script

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下作者

支付宝扫一扫打赏

微信扫一扫打赏