33 lines
733 B
Bash
33 lines
733 B
Bash
#!/bin/sh
|
|
|
|
if [ ! -f "start.sh" ] || [ ! -f "stop.sh" ]; then
|
|
echo "current folder should have start.sh and stop.sh"
|
|
exit 1
|
|
fi
|
|
|
|
workdir=$(pwd)
|
|
servicename=$(basename `pwd`)
|
|
sudo cat >$servicename.service <<EOF
|
|
[Unit]
|
|
Wants=systemd-networkd.service
|
|
|
|
[Service]
|
|
Type=forking
|
|
WorkingDirectory=$workdir
|
|
ExecStart=$workdir/start.sh
|
|
ExecStop=$workdir/stop.sh
|
|
StandardOutput=append:/var/log/$servicename/$servicename.log
|
|
StandardError=append:/var/log/$servicename/$servicename.log
|
|
SyslogIdentifier=$workdir
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
sudo cp $servicename.service /etc/systemd/system
|
|
sudo mkdir /var/log/$servicename
|
|
sudo systemctl daemon-reload
|
|
sudo systemctl enable $servicename
|
|
sudo systemctl restart $servicename
|
|
|