How to rewrite systemd unit to init script?

Hi there! I have this systemd unit for useful service:

[Unit]
Description=Opera VPN
Documentation=https://github.com/Snawoot/opera-proxy/
After=network.target network-online.target
Requires=network-online.target

[Service]
EnvironmentFile=/etc/default/opera-proxy
User=nobody
Group=nogroup
ExecStart=/usr/local/bin/opera-proxy $OPTIONS
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full

[Install]
WantedBy=default.target

How to rewrite this unit for Openwrt init script?

make a copy of a simple /etc/init.d service, like firewall, and adapt it to your needs.

1 Like

Ok, now I have this script and it works like a charm

#!/bin/sh /etc/rc.common
# opera-proxy 

START=99
STOP=1

USE_PROCD=1
PROG=/usr/bin/opera-proxy

start_service() {
    procd_open_instance
    procd_set_param command $PROG $(cat /etc/config/opera-proxy)
    procd_set_param timeout ${TimeoutStopSec:-5s}
    procd_set_param limits nofile=${LimitNOFILE:-1048576} nproc=${LimitNPROC:-512}
    procd_set_param env TMPDIR=/tmp
    procd_set_param stdout 1
    procd_set_param stderr 1
    procd_set_param respawn
    procd_set_param respawn_delay 5
    procd_close_instance
}

stop_service() {
    procd_close_instance
}

start() {
    echo "Starting Opera VPN..."
    start_service
}

stop() {
    echo "Stopping Opera VPN..."
    stop_service
}

restart() {
    stop
    sleep 1
    start
}

any ideas for improvement?
and how to send the output to the OpenWrt log?

By default

    procd_set_param stdout 1
    procd_set_param stderr 1

Should forward stdout/stderr of the command to logd. See Defining Service Instances.

You could also, within the script use:

# Write a message with a tag to syslog (logd)
logger -t TAG MESSAGE

and

# List syslog filtered by tag
logread -e TAG

wiki here

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.