Skip to content

Instantly share code, notes, and snippets.

@akillcool
Last active March 19, 2024 01:43
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 12 You must be signed in to fork a gist
  • Save akillcool/40e4021f8063bae8274217d5747eb3ca to your computer and use it in GitHub Desktop.
Save akillcool/40e4021f8063bae8274217d5747eb3ca to your computer and use it in GitHub Desktop.
clash auto start and update subcribe configuration
# edit and save this file to /usr/lib/systemd/system/clash.service
[Unit]
Description=clash
After=network.target
[Service]
WorkingDirectory="your home directory"/.config/clash
ExecStart="your home directory"/.config/clash/start-clash.sh
ExecStop="your home directory"/.config/clash/stop-clash.sh
Environment="HOME=your home directory"
Environment="CLASH_URL=your subscribe address"
[Install]
WantedBy=multi-user.target
#!/bin/bash
# save this file to ${HOME}/.config/clash/start-clash.sh
# save pid file
echo $$ > ${HOME}/.config/clash/clash.pid
diff ${HOME}/.config/clash/config.yaml <(curl -s ${CLASH_URL})
if [ "$?" == 0 ]
then
/usr/bin/clash
else
TIME=`date '+%Y-%m-%d %H:%M:%S'`
cp ${HOME}/.config/clash/config.yaml "${HOME}/.config/clash/config.yaml.bak${TIME}"
curl -L -o ${HOME}/.config/clash/config.yaml ${CLASH_URL}
/usr/bin/clash
fi
#!/bin/bash
# save this file to ${HOME}/.config/clash/stop-clash.sh
# read pid file
PID=`cat ${HOME}/.config/clash/clash.pid`
kill -9 ${PID}
rm ${HOME}/.config/clash/clash.pid
@skychecker
Copy link

how to configure this in docker deployment ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment