Linux is configured with Clash auto-start with auto-update subscriptions.
Supports user-defined port numbers and subscription addresses.
Operation principle: Shell script downloads subscription content and starts Clash, systemctl configuration starts automatically after startup
Prerequisites: Clash has been installed
github.com/juewuy/Shel…
GitHub has found a more complete project called ShellClash, which has a similar principle but is much easier to configure
clash.service
/lib/systemd/system/clash.service
[Unit]
Description=clash
Requires=network-online.target
After=network.target network-online.target
[Service]
ExecStart=/etc/clash/start-clash.sh
ExecStop=/etc/clash/stop-clash.sh
EnvironmentFile=/usr/share/clash/CLASH_ENV
[Install]
WantedBy=multi-user.target
Copy the code
start-clash.sh
/etc/clash/start-clash.sh
#! /bin/bash
echo $$ > /var/run/clash.pid
DIRECTORY_PATH=/etc/clash
CONFIG_YAML=`curl ${CLASH_URL} -s --max-time 10 --retry 3`
if[$? = 0];then
echo "${CONFIG_YAML}" > ${DIRECTORY_PATH}/config.yaml
# Customize mixed-port
if [ -n "${MIXED_PROT}" ]; then
sed -i "1i\mixed-port: ${MIXED_PROT}" ${DIRECTORY_PATH}/config.yaml
fi
fi
/usr/bin/clash -d /usr/share/clash
Copy the code
Add the run permission: chmod +x start-clash.sh
stop-clash.sh
/etc/clash/stop-clash.sh
#! /bin/bash
PID=`cat /var/run/clash.pid`
kill9 -${PID}
rm /var/run/clash.pid
Copy the code
Add run permission: chmod +x stop-clash.sh
CLASH_ENV
/etc/clash/CLASH_ENV
MIXED_PROT=1080Copy the code
Add view permission: chmod +r CLASH_ENV
Start the
systemctl start clash
Script from the rev.
systemctl enable clash