Converting init.d script to systemctl.
I need to convert a init.d script to systemctl.
In the start() function of my init.d script I have this code:
start() {
echo -n "Starting SSL-SSH-Switch: "
if [ -f $PIDFILE ]; then
PID=`cat $PIDFILE`
echo sslh already running: $PID
exit 2;
else
daemon --user myuser $SSLH $OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch $PIDFILE
[ $RETVAL -eq 0 ] && touch $lockfile
ip rule add fwmark 0x1 lookup 100;
ip route add local 0.0.0.0/0 dev lo table 100;
return $RETVAL
fi
}
How can I insert this lot of command in a systemctl script?
Can you make an example please?
2 Replies
[Unit]
Description=SSL-SSH-Switch
[Service]
# (or Type=forking, if sslh does actually "daemonize" itself)
Type=simple
User=myuser
ExecStart=/usr/bin/sslh --whatever
ExecStartPost=/usr/bin/ip rule add fwmark 0x1 lookup 100
ExecStartPost=/usr/bin/ip route add local 0.0.0.0/0 dev lo table 100
# (probably)
# ExecStopPost=/usr/bin/ip route del local 0.0.0.0/0 dev lo table 100
# ExecStopPost=/usr/bin/ip rule del fwmark 0x1 lookup 100
[Install]
WantedBy=multi-user.target
Related: