備忘録。
たまに作るとなんだっけ?となるのでここに自作スクリプト書いておく。
#!/bin/bash
unitname=softether-vpn.service
unitfile=/etc/systemd/system/$unitname
tempfile=$(mktemp)
ifname=$(ip -o link show | grep ^2 | sed -e "s/://g" | awk '{ print $2 }')
cat << EOS >> $tempfile
[Unit]
Description=Softether VPN Server Service
After=network.target
[Service]
Type=forking
User=root
ExecStart=/usr/local/vpnserver/vpnserver start
ExecStop=/usr/local/vpnserver/vpnserver stop
Restart=on-abort
WorkingDirectory=/usr/local/vpnserver
ExecStartPre=/sbin/ip link set dev $ifname promisc on
[Install]
WantedBy=multi-user.target
EOS
cp -pvf "$tempfile" "$unitfile"
[ -f "$tempfile" ] && rm -f "$tempfile"
systemctl daemon-reload
systemctl enable $unitname
systemctl start $unitname