What's new
  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

How to list services, start / stop services via script?

nickolasm5

Occasional Visitor
Hello,

I am trying to set up a script that will check OpenVPN connection, if that fails - restart sevice. The service that is needed to be restarted is Amnezia Cloak.

Now I've created without issues - checking the state -
if ifconfig tun11 | grep -q "00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00"
then
echo "VPN up"
else
echo "VPN down"
fi
exit 0

Yet I can't find a way how to list already running services. service --status-all just writes Done.
How can I see the list of services and their status?
What is the correct way to add the needed service to be stopped to the script above?
 
service is a bespoke Asus command. It is not the same command you would find in a Linux distro therefore service --status-all is not valid. asuswrt doesn't have an equivalent command as it doesn't use System V inits script or run systemd.

The service that is needed to be restarted is Amnezia Cloak.
How have you installed this software?
 
service is a bespoke Asus command. It is not the same command you would find in a Linux distro therefore service --status-all is not valid. asuswrt doesn't have an equivalent command as it doesn't use System V inits script or run systemd.


How have you installed this software?
Yes, the service is started via sript and works perfect. Yet it can fail if there are some connection issues - I wan't to run periodic checks to make sure it runs (start it back if needed)
basiclally I want to find how to check if the service is up and stop / restart it (I even don't know how it is named within OS now)
 
You would have to check whether the process (not service) is running with something like this:
Rich (BB code):
if [ -z "$(pidof myprocessname)" ]
then
   # restart service
fi
 
You would have to check whether the process (not service) is running with something like this:
Rich (BB code):
if [ -z "$(pidof myprocessname)" ]
then
   # restart service
fi
but how do I know the name of the process? or its pid?
I cold find the PID using top command, yet would it always be the same (4430)?
1744108210356.png
 
Last edited:
I don't know as you've refused to give any details about this software or how you installed it on your router (or what router you're using). 🤷‍♂️
the description of the software - https://github.com/cbeuw/Cloak
I created the sript that starts the software (client) on services start
the prosess starts and works correctly, yet - e.g. if the WAN cable is unpluged for some time or any other similar reason, the service needs to be restarted to regain connection
 
e.g. if the WAN cable is unpluged for some time or any other similar reason, the service needs to be restarted to regain connection
You should see if the wan-event script is more appropriate to detect “connected” state changes and trigger your script from there.

Of course, none of this would work on boot until you can be sure the USB is mounted first.
 
seems to work like that:
for pid in `ps -w | grep "ck-client" | awk '{print $1}'`
do
echo "killing $pid"
kill -9 $pid
done

the scirpt that starts cloak client:

/mnt/sda1/usr/bin/ck-client -s xxx.xxx.xxx.xxx -l 1984 -c /mnt/sda1/etc/config/cloak/ckclient.json

Maybe there are better ideas?
 
one more question - is it possible, and if yes - how to add echos from the scripts to system log that is visible in the GUI?
 
one more question - is it possible, and if yes - how to add echos from the scripts to system log that is visible in the GUI?
Use logger instead of echo.
Code:
Usage: logger [OPTIONS] [MESSAGE]

Write MESSAGE (or stdin) to syslog

        -s      Log to stderr as well as the system log
        -c      Log to console as well as the system log
        -t TAG  Log using the specified tag (defaults to user name)
        -p PRIO Priority (numeric or facility.level pair)

Code:
logger "My Test Message"
 

Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Back
Top