Shadowsocks Scheduled Task Script

Shadowsocks

Quite a few people have reported that after using Shadowsocks for a while, its process disappears.
In fact, in most cases, it has been killed by the system.
To be sure, some cases are caused by the VPS, and some by Shadowsocks
itself. For example, the memory may be too small, or using multiple ports for a period of time may cause memory usage to become too high, resulting in insufficient memory, and so on.
With this in mind, I wrote a Shadowsocks
process-checking script that will restart it once it detects that the process no longer exists.

Log in as the root user and run the following commands:

wget --no-check-certificate https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocks-crond.sh
chmod +x shadowsocks-crond.sh

At this point, the script shadowsocks-crond.sh has been downloaded and given execute permission.

Next, just put this script into Linux’s cron scheduled tasks and you’re done.
cron is a scheduled execution tool on Linux
that can run jobs without manual intervention. Since
Cron is a built-in Linux
service, in most cases it does not start automatically. You can use the following methods to start or stop this service.

/etc/init.d/crond start //start the service
/etc/init.d/crond stop //stop the service
/etc/init.d/crond restart //restart the service
/etc/init.d/crond reload //reload the configuration

Edit the /etc/crontab file to configure cron
By default, it looks like this:

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed

Just append the following line at the end:

*/5 * * * * root bash /root/shadowsocks-crond.sh

Then save and exit.
This means that every 5 minutes, the root user will execute the script
/root/shadowsocks-crond.sh
Note that the script path must be written in full.

This way, the system will check every 5 minutes whether the Shadowsocks
process exists, and if it does not, it will automatically restart it.
The script writes logs each time it runs. The full log path is as follows:

/var/log/shadowsocks-crond.log

If you have time, you can check that log file to see whether the Shadowsocks
process really does often disappear. If that is indeed the case, I’m afraid you’ll need to investigate the deeper cause.

Updated on December 05, 2016:

Leave a Comment

Your email address will not be published. Required fields are marked *

中文 EN
🚀

RedGate VPN

免费节点太挤太慢?
升级高速稳定专线

立即体验 →

告别卡顿

RedGate VPN
全球高速节点

免费下载 →
Scroll to Top