Converting init.d script to systemctl.

Hi,

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

You don't need most of those commands.

[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: ~~[http://0pointer.de/blog/projects/systemd-for-admins-3.html" target="_blank">](http://0pointer.de/blog/projects/system … ins-3.html">http://0pointer.de/blog/projects/systemd-for-admins-3.html](

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct