-
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Modularize service management with functions
- Added run_as_su, stop_service, and start_service for better readability and reuse. - Improved process check with /proc/${PID}.
- Loading branch information
1 parent
aab2112
commit d9cc218
Showing
1 changed file
with
26 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,33 @@ | ||
#!/system/bin/sh | ||
|
||
box_dir=/data/adb/box | ||
# Definisi variabel | ||
box_dir="/data/adb/box" | ||
box_run="${box_dir}/run" | ||
box_pid="${box_run}/box.pid" | ||
|
||
if [ -f "${box_pid}" ]; then | ||
echo "正在关闭服务…" | ||
run_as_su() { | ||
su -c "$1" | ||
} | ||
|
||
stop_service() { | ||
echo "Service is shutting down" | ||
su -c $box_dir/scripts/box.iptables disable && su -c $box_dir/scripts/box.service stop | ||
run_as_su "${box_dir}/scripts/box.iptables disable" | ||
run_as_su "${box_dir}/scripts/box.service stop" | ||
} | ||
|
||
start_service() { | ||
echo "Service is starting, please wait for a moment" | ||
run_as_su "${box_dir}/scripts/box.service start" | ||
run_as_su "${box_dir}/scripts/box.iptables enable" | ||
} | ||
|
||
if [ -f "${box_pid}" ]; then | ||
PID=$(cat "${box_pid}") | ||
if [ -e "/proc/${PID}" ]; then | ||
stop_service | ||
else | ||
start_service | ||
fi | ||
else | ||
echo "正在启动服务,请耐心等待…" | ||
echo "Service is starting,please wait for a moment" | ||
su -c $box_dir/scripts/box.service start && su -c $box_dir/scripts/box.iptables enable | ||
exit | ||
fi | ||
start_service | ||
fi |