[TEMPORARY FIX][TWEAK][MT6582] Xposed Installer Log File Gets Big - Xposed General

Hi All,
I am a happy user of Xposed Installer and using Modules.
However, one day my friend asked me if I could help him to fix the logging problems of Xposed because it almost ate like ~500MB of his internal space without him knowing it. So, I made this simple script to make a temporary fix (although I can still make this a little more flexible by checking the log file instead of running it on a fixed interval). I hope this helps and I hope Xposed dev can make an option to cleanup the logs generated by the modules.
More power
The script - I found that (not really proven, but as observed) looping scripts in the init.d are not very well handled so I did a workaround. I have the main script (cleaner) inside data and one script (trigger) in init.d. So here are they:
The main script - I placed on /data/Tweaks/scripts:
Code:
#!/system/bin/sh
# Name: 50_XposedCleanLog
# Date: 10/27/2014
# Author: Arsie Organo Jr. - [email protected]
# Link:
# About: This will clean up Xposed Installer app generated
# logs every X minutes.
# 1. Rooted
# 2. Busybox is installed.
####################################################
# Interval between 50_XposedCleanLog runs, in seconds, 18000=.5hour
XPOSEDLOGS=/data/data/de.robv.android.xposed.installer/log/error.log
a=0
sleepme=18000
while [ $a -ge 0 ]
do
busybox rm -f $XPOSEDLOGS
busybox touch $XPOSEDLOGS
chown root:root $XPOSEDLOGS
echo "Xposed Logs Cleanup Started $( date +"%m-%d-%Y %H:%M:%S" )" | tee -a $XPOSEDLOGS;
echo "Cleanup will run again in the next $(expr $sleepme / 60) min" | tee -a $XPOSEDLOGS;
echo $a
a=`expr $a + 1`
echo "Xposed Logs cleaner completed at $( date +"%m-%d-%Y %H:%M:%S" )" | tee -a $XPOSEDLOGS;
sleep $sleepme
done
# END
And the trigger is placed in /system/etc/init.d - 10_DONOTDELETE:
Code:
#!/system/bin/sh
# Name: 10_DONOTDELETE
# Date: 10/28/2014
# Author: Arsie Organo Jr. - [email protected]
# Link:
# About: This script is needed to run all the tweaks
# and looping scripts.
# You will need your device to be:
# 1. Rooted
# 2. Busybox is installed.
####################################################
datalog=/data/Tweaks/logs/10_DONOTDELETE.log
busybox rm -f $datalog
busybox touch $datalog
# Xposed logs cleaner
/system/bin/sh /data/Tweaks/scripts/50_XposedCleanLog.sh > /dev/null 2>&1 &
if [ `busybox ps -ef | grep Tweaks | grep 50_XposedCleanLog.sh | wc -l` -eq 1 ] ;
then
echo "$( date +"%m-%d-%Y %H:%M:%S" ) Xposed logs cleaner initiated" | tee -a $datalog;
else
echo "$( date +"%m-%d-%Y %H:%M:%S" ) Xposed logs cleaner initialization FAILED" | tee -a $datalog;
fi;
So this simply means that the main script will be called upon restart and then loop it in the background checking the log file every 30min.
Note: Phone needs to be rooted and must have busybox installed. Tested on MediaTek MT6582 (MP Agua Rio) JB version.
I have attached a flashable here.. direct flash only and there is no need to wipe your cache.
This will work ONLY if your phone supports init.d and the generated Xposed log file is located here - /data/data/de.robv.android.xposed.installer/log/error.log

Wow very nice keep it up sir. :good:

Rovo89 set limit for log file to 5 MB. https://github.com/rovo89/XposedBridge/commit/afcc3e1e788ea44bfd00245a24b5dfe6c86aa3d0

Cool!
pyler said:
Rovo89 set limit for log file to 5 MB. https://github.com/rovo89/XposedBridge/commit/afcc3e1e788ea44bfd00245a24b5dfe6c86aa3d0
Click to expand...
Click to collapse
That's cool, however using the latest Xposed (experimental version) we've seen the error.log can go more than 500mb.
You can check the ridiculous size of the error.log below. So to aid this, I made this looping script.

eyesfortech said:
That's cool, however using the latest Xposed (experimental version) we've seen the error.log can go more than 500mb.
You can check the ridiculous size of the error.log below. So to aid this, I made this looping script.
Click to expand...
Click to collapse
Yes, this change is not part of 2.7 exp1.

too bad but there is always hope
pyler said:
Yes, this change is not part of 2.7 exp1.
Click to expand...
Click to collapse
yeah... I guess so, but there's always hope

huge issue
I check and mine is 7gb but when I check application manager it says xposed is using 11gb why?

manual Clear logs
bigchuk00 said:
I check and mine is 7gb but when I check application manager it says xposed is using 11gb why?
Click to expand...
Click to collapse
Hi,
have you tried manually clearing the logs from Xposed Logs options?

No. I didn't. The flash able zip was what I used n it worked fine . thank you.

Cool! I guess the permanent solution will be provided in the next update of Xposed (hopefully!)

It's just absurd that these 'error logs' rack up over a 100mb per day. The Xposed chappies say look at the log to see what module is causing the problem - well, I can't make head nor tail of the logs. Should be a better way of dealing with it.

eyesfortech said:
Cool! I guess the permanent solution will be provided in the next update of Xposed (hopefully!)
Click to expand...
Click to collapse
I admire your genius in setting up cron & it works flawlessly on my device, please would be able to create a flashable script or cron that will make @zeppelinrox sclean(wipe dalvik & reboot) script to run once each week?

slimcyril said:
I admire your genius in setting up cron & it works flawlessly on my device, please would be able to create a flashable script or cron that will make @zeppelinrox sclean(wipe dalvik & reboot) script to run once each week?
Click to expand...
Click to collapse
Unfortunately I am currently swamped with my day job and I cannot promise anything sooner. Can you give me the link the one you wanted me to try? And on what device? Currently I am no longer using MTK so testing it will also be a problem.
Thanks.

eyesfortech said:
Unfortunately I am currently swamped with my day job and I cannot promise anything sooner. Can you give me the link the one you wanted me to try? And on what device? Currently I am no longer using MTK so testing it will also be a problem.
Thanks.
Click to expand...
Click to collapse
Thanks for your response I later found what I was looking here http://forum.xda-developers.com/showthread.php?t=2700146

Related

[STOCK]INIT.D support. No need to flash anything or even reboot into recovery

So yea I've been working on a proper "app2sd" solution that doesn't involve just switching the MicroSD for the eMMC, but I like the stock rom so far, so I didn't feel like flashing a rom just to get init.d, and I didn't feel like modifying the ramdisk in the kernel either. So I cooked up this script that anyone can run from terminal to get init.d support. It should work for other devices too, as long as they run /system/etc/install-recovery.sh on boot.
There's only three requirements for it to work:
#1 You must be rooted
#2 Your device must run /system/etc/install-recovery.sh
#3 You must have busybox
I tested a few times on my own device (GT-N8013), but haven't had anyone else test it, so don't freak out if it doesn't work. Just let me know what went wrong and I'll figure something out.
Running it is very simple:
#1 Open any terminal app
#2 su
#3 navigate to the folder where you have the script
#4 sh ./enableinit.sh
Your device will be rebooted once the process is done, don't freak out. If everything went fine, you'll have a file in /sdcard called init.d.log created by the test init.d script that is made by the enabler.
You can either download the attachment (rename it to enableinit.sh if you get the attachment), or create the file with the contents betlow:
Code:
#!/system/bin/sh
# Adds init.d support to any device that automatically runs /system/etc/install-recovery.sh
# on startup.
#
# Made by TweakerL, make sure to visit us at and-host.com or chat with us on freenode #and-host
echo '##################################################'
echo '## ##'
echo '## Script by TweakerL ##'
echo '## Visit us at and-host.com ##'
echo '## Chat with us at freenode #and-host ##'
echo '## ##'
echo '##################################################'
echo ''
echo 'This script will enable init.d if your device'
echo 'executes /system/etc/install-recovery.sh'
echo ''
echo 'Your tablet will be rebooted once the process'
echo 'is done.'
echo ''
echo 'If the script successfully enabled init.d you will'
echo 'have a file in /sdcard called init.d.log after'
echo 'the device is done rebooting. Remember to always'
echo 'set the proper permissions in your scripts or they'
echo 'will not work.'
echo ''
read -p "Press ENTER to continue..."
if [ ! -f /system/xbin/busybox -a ! -f /system/bin/busybox ]
then
echo 'You do not have busybox. Exiting now...'
else
# Mount system as rw in order to execute the script
busybox mount -o remount,rw -t ext4 /dev/block/mmcblk0p9 /system
# Check if install-recovery.sh already exists, and if so
# add the necessary lines, otherwise create it
if [ -f /system/etc/install-recovery.sh ]
then
if cat /system/etc/install-recovery.sh | busybox egrep -i "sysinit"
then
echo sysinit already present in install-recovery.sh, skipping this step.
else
busybox cp -f /system/etc/install-recovery.sh /sdcard/qsxdrgbhuk.sh
echo '' >> /sdcard/qsxdrgbhuk.sh
echo '/system/bin/sysinit' >> /sdcard/qsxdrgbhuk.sh
busybox cp -f /sdcard/qsxdrgbhuk.sh /system/etc/install-recovery.sh
fi
else
echo '#!/system/bin/sh' >> /sdcard/qsxdrgbhuk.sh
echo '' >> /sdcard/qsxdrgbhuk.sh
echo '/system/bin/sysinit' >> /sdcard/qsxdrgbhuk.sh
busybox cp -f /sdcard/qsxdrgbhuk.sh /system/etc/install-recovery.sh
busybox chmod 755 /system/etc/install-recovery.sh
fi
# Check if sysinit already exists and if so skip step
# otherwise create it
if [ ! -f /system/bin/sysinit ]
then
echo '#!/system/bin/sh' >> /sdcard/kuhbgrdxsq
echo 'export PATH=/sbin:/system/sbin:/system/bin:/system/xbin' >> /sdcard/kuhbgrdxsq
echo '' >> /sdcard/kuhbgrdxsq
echo '/system/bin/logwrapper busybox run-parts /system/etc/init.d' >> /sdcard/kuhbgrdxsq
busybox cp -f /sdcard/kuhbgrdxsq /system/bin/sysinit
busybox chmod 755 /system/bin/sysinit
else
echo sysinit already exists in /system/bin. init.d should already be enabled.
fi
# Cleanup
busybox rm -f /sdcard/qsxdrgbhuk.sh
busybox rm -f /sdcard/kuhbgrdxsq
#Check that init.d folder exists and if not create it
# as well as set the right permissions
if [ -d '/system/etc/init.d' ]
then
chmod 755 /system/etc/init.d
else
mkdir /system/etc/init.d
chmod 755 /system/etc/init.d
fi
# Create a test init.d script that echoes a file to
# /sdcard on successful execution
echo '#!/system/bin/sh' > /sdcard/99testinit
echo '' >> /sdcard/99testinit
echo 'echo init.d works > /sdcard/init.d.log' >> /sdcard/99testinit
busybox cp -f /sdcard/99testinit /system/etc/init.d
chmod 755 /system/etc/init.d/99testinit
busybox rm -f /sdcard/99testinit
# Sync and remount system
sync
busybox mount -o remount,ro -t ext4 /dev/block/mmcblk0p9 /system
# Reboot system to enable init.d
if [ -f /system/bin/reboot ]
then
echo Your device will reboot in 3 seconds
sleep 3
reboot
else
echo "Your device doesn't appear to have a reboot command,"
echo "please reboot your device now to avoid problems."
fi
fi
reserved
TweakerL said:
reserved
Click to expand...
Click to collapse
it is good!
TweakerL said:
reserved
Click to expand...
Click to collapse
Thanks for sharing.
Im tested my ainol elf offical rom novo0706, and worked. Thank
Sent from my Ainol Novo 7 Elf using Tapatalk 2
Pretty awesome. Will edit once i try this out.
Edit: Everything worked. Tested on GT-N8013
Thanks alot.
Sent from my GT-N8013 using Tapatalk 2
Hi, Can you tell more clearly how to make this work.
Sent from my GT-N8000 using xda app-developers app
Can any one make .zip file to flash thru recovery..thanks
The point was not to have to go into recovery...
Anyway, it's really simple...
Download the attached file
open terminal
then do the following commands
Code:
su
cd /sdcard
sh ./Download/enableinit.sh.txt
assuming that your browser saves files to /sdcard/Download
Sorry, I am a computer idiot . I really donot how to do after I had downloaded the text file. Appreciated if you can explain more detail.
Sent from my GT-N8000 using xda app-developers app
So now with init.d support ready, is it going to be possible to run proper a2sd scripts? And which one specifically would you recommend? Excuse me if i'm asking the wrong questions.
andylam16 said:
Sorry, I am a computer idiot . I really donot how to do after I had downloaded the text file. Appreciated if you can explain more detail.
Sent from my GT-N8000 using xda app-developers app
Click to expand...
Click to collapse
It has nothing to do with knowing anything about computers, as you don't need a computer to do this... just your device...
Download the file, on your device, if you're using stock browser it will go to /sdcard/Download
Make sure you have busybox, download a busybox installer from the market, install it, and run it, and tell it to install busybox
Download a terminal app from the play store for free, such as android terminal emulator, install it and open it
then type in these exact commands, just like they're in here, in the terminal:
Code:
su
sh /sdcard/Download/enableinit.sh
Assuming of course, that your stuff is getting download to /sdcard/Download.
If you can't do this... sell your android device and buy an iCrap one...
drnish83 said:
So now with init.d support ready, is it going to be possible to run proper a2sd scripts? And which one specifically would you recommend? Excuse me if i'm asking the wrong questions.
Click to expand...
Click to collapse
I'm working on my own app2sd script that should beat anything ever made. Here's what it does:
It uses a second partition in the MicroSD card for gaining extra storage, this partition has to be formatted to ext4
#1 It mounts the external ext4 partition to a new location
#2 It detects the location for /sdcard/Android; /data/data; /data/app no matter what device you have (suppose the directories aren't the same for a certain device)
#3 It has the option to mount /sdcard/Android to a folder in the external partition
#4 It has the option to mount /data/data to a folder in the external partition
#5 It has the option to mount /data/app to a folder in the external partition
#6 It has the option to automatically copy everything from any of those folders to the appropriate folder in the external partition
#7 It has the option to automatically wipe from the internal storage anything that it moves
#8 If you have all options enabled, apps will be automatically installed to the external partition and never take any space in the internal storage, while everything else (Download/recovery/backup/pictures/videos/etc...) all remain in the internal partition.
Wow... cant wait for this script
Sent from my GT-N8013 using Tapatalk 2
Thanks for explaining. Interesting indeed! Will definitely wait for it eagerly!
Here's a preview of the super app2sd script I'm working on. Much of it is already implemented, should have it all in a couple of days
confusing
I have tried your script and it has successful at first.. then i flashing my note again with stock rom and i try using ur script again but now there is nothing chance.. do you know why?? what must i do now??
You know, this is the damnedest thing, but your instructions call for Busybox installation, and I can't install Busybox on my N8013. And tips you can share?
NessLookAlike said:
You know, this is the damnedest thing, but your instructions call for Busybox installation, and I can't install Busybox on my N8013. And tips you can share?
Click to expand...
Click to collapse
Busy box installs on mine.
Sent from my GT-N8013 using Tapatalk 2
NessLookAlike said:
You know, this is the damnedest thing, but your instructions call for Busybox installation, and I can't install Busybox on my N8013. And tips you can share?
Click to expand...
Click to collapse
Only reason you wouldn't be able to install busybox is if you're not rooted.
Mr tweaker, i have done the process of init.d but there is nothing changed.. where is my false?
Sent from my GT-N8000 using XDA Premium HD app
Welly_11 said:
Mr tweaker, i have done the process of init.d but there is nothing changed.. where is my false?
Sent from my GT-N8000 using XDA Premium HD app
Click to expand...
Click to collapse
Look for these files and let me know if they're there:
/system/etc/install-recovery.sh
/system/bin/sysinit
/system/etc/init.d/99testinit
**************************************
If anybody needs help, look for me on irc - #and-host in freenode

[Q] Init.d under Cocore 6.2 dont working [SOLVED]

Hi
Im using Galaxy S Advance with:
JB 4.1.2 and stock ROM
rooted
kernel Cocore 6.2
I tried to use script on boot from init.d directory, unfortunately not working.
To see if it works fine, I created /etc/init.d folder
with permissions 777, owner root
Inside init.d folder, I created simple script: testinit.sh also testinit
Code:
#!/system/bin/sh
echo init.d script is working > /storage/sdcard0/init.txt
file permissions 777, owner root
But after restart, file init.txt on sdcard0 isnt created,
so I suppose that script isnt running.
I created also another script follow Cocore thread
Code:
#!/system/bin/sh
insmod /lib/modules/logger.ko
for start logger. Logger didnt start also.
Both scripts started in console or adb works fine.
Tnx in advance
darcik said:
Hi
Im using Galaxy S Advance with:
JB 4.1.2 and stock ROM
rooted
kernel Cocore 6.2
I tried to use script on boot from init.d directory, unfortunately not working.
To see if it works fine, I created /etc/init.d folder
with permissions 777, owner root
Inside init.d folder, I created simple script: testinit.sh also testinit
Code:
#!/system/bin/sh
echo init.d script is working > /storage/sdcard0/init.txt
file permissions 777, owner root
But after restart, file init.txt on sdcard0 isnt created,
so I suppose that script isnt running.
I created also another script follow Cocore thread
Code:
#!/system/bin/sh
insmod /lib/modules/logger.ko
for start logger. Logger didnt start also.
Both scripts started in console or adb works fine.
Tnx in advance
Click to expand...
Click to collapse
Try this way: LINK.
Tnx for answer, atm I abandoned testinit script, this isnt important
and focused on start of logger .
I changed it to
Code:
#!/system/bin/sh
busybox mount -o remount,rw -t auto /system;
busybox insmod /lib/modules/logger.ko
but logger didnt start.
Does the system log, what happens when boot, I mean errors?
I have a habit of "big" Linux system
darcik said:
Tnx for answer, atm I abandoned testinit script, this isnt important
and focused on start of logger .
I changed it to
Code:
#!/system/bin/sh
busybox mount -o remount,rw -t auto /system;
busybox insmod /lib/modules/logger.ko
but logger didnt start.
Does the system log, what happens when boot, I mean errors?
I have a habit of "big" Linux system
Click to expand...
Click to collapse
I think log starts after script is executed, and it can't be executed during pre-boot. So maybe it only works when you get in system (booted). And then there is not much to show, try doing some thing while logcat is triggered. Like change governor, IO etc.
I am just gessing this, maybe I am wrong about that, but seams logical to me. :fingers-crossed:
Lol
Incidentally, I found the answer to my problem in this topic.
Save the script without any extensions (Yes, not even .sh extension).
Click to expand...
Click to collapse
So I renamed my script to logcat without sh extension and all works.
Anyway tnx for help.
Cocore 8.0 init.d not working
I make this init.d file for cocore 8.0:
#!/system/bin/sh
busybox mount -o remount,rw -t auto /system;
echo 12 > /sys/module/mxt224e/parameters/threshold_batt
echo init.d script is working > /storage/sdcard0/init.txt
echo "pegasusq" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo "sio" > /sys/block/mmcblk0/queue/scheduler
echo 100663296 > /sys/block/zram0/disksize
mkswap /dev/block/zram0
swapon /dev/block/zram0
echo 700 > /sys/kernel/abb-charger/max_ac_c
echo 0 > /sys/module/mali/parameters/mali_debug_level
Click to expand...
Click to collapse
placed in /system/etc/init.d with "logcat" name. This scirpt don't make the txt file. Why?
Permission 755 for script file. No .sh at the end - just filename.
That should help
Sent from my SGS Adv. using xda-developers app.
th3cr0w said:
Permission 755 for script file. No .sh at the end - just filename.
That should help
Sent from my SGS Adv. using xda-developers app.
Click to expand...
Click to collapse
The solution was i left some space after the command. Thank you!

[SOLVED] Cannot change LMK minfree values with script in /magisk/.core/service.d

Dear Community, dear Developers outside..
I'm using Magisk 14.0 on a Redmi Note 4 Snapdragon and super satisfied with it.
I just want to make simple changes like changing the lowmemorykiller minfree parameters - just like an init.d script in Kernel Adiutor..
Most of the commands are effective - but some of them are not..
This is what I want to apply for example:
chmod 666 /sys/module/lowmemorykiller/parameters/minfree
chown root /sys/module/lowmemorykiller/parameters/minfree
echo '7283,14566,21849,28928,36415,43698' > /sys/module/lowmemorykiller/parameters/minfree
..but does not work..
But these, for example.. these are working just fine:
echo '30' > /proc/sys/vm/swappiness
echo '0' > /sys/module/lowmemorykiller/parameters/enable_adaptive_lmk
echo '80' > /proc/sys/vm/overcommit_ratio
echo '400' > /proc/sys/vm/vfs_cache_pressure
echo '2430' > /proc/sys/vm/extra_free_kbytes
echo '4096' > /proc/sys/kernel/random/write_wakeup_threshold
echo '1024' > /sys/block/mmcblk0/queue/read_ahead_kb
echo '0' > /sys/block/mmcblk0/queue/iostats
echo '1' > /sys/block/mmcblk0/queue/add_random
echo '1024' > /sys/block/mmcblk1/queue/read_ahead_kb
echo '0' > /sys/block/mmcblk1/queue/iostats
echo '1' > /sys/block/mmcblk1/queue/add_random
swapoff /dev/block/zram0 > /dev/null 2>&1
echo '1' > /sys/block/zram0/reset
echo '0' > /sys/block/zram0/disksize
echo '1' > /sys/block/zram0/max_comp_streams
echo '524288000' > /sys/block/zram0/disksize
mkswap /dev/block/zram0 > /dev/null 2>&1
swapon /dev/block/zram0 > /dev/null 2>&1
echo '4096' > /proc/sys/kernel/random/read_wakeup_threshold
echo '4096' > /proc/sys/vm/min_free_kbytes
echo '0' > /proc/sys/vm/oom_kill_allocating_task
echo '90' > /proc/sys/vm/dirty_ratio
echo '70' > /proc/sys/vm/dirty_background_ratio
I do know that all I have to do is to put my script to one of these dirs - depending on when I want to run the scripts:
/magisk/.core/service.d
/magisk/.core/post-fs-data.d
But, as I mentioned - most of them has effect, some of them has no..
Any comment, any suggestion is more than appreciated.
Thank you!
[SOLVED] - solution is in post #5
Desperate bump..
I searched for help docs for service.d and post-fs-data.d but counldn't find them, can I ask you when each folder is executed, also does the scripts inside them must have .sh extension or not ?
I want to restart my systemui after boot complete, can you tell me if this script is ok ?
Code:
#!system/bin/sh
sleep 20
su
pkill -l TERM -f com.android.systemui
ps : the pkill command works fine after an "su" in terminal emulator
sorry for the offtopic !
@sheraro
https://github.com/topjohnwu/Magisk/blob/master/docs/README.MD
First of all: the solution for my issue was a simple sleep 30 in the services.sh to delay the start.. and I used an auxiliary file as well to make the changes (called from services.sh with 30sec delay, copied with the update-binary file directly, set permission to 0777 via config.sh) after that is all started working..
sheraro said:
I searched for help docs for service.d and post-fs-data.d but counldn't find them, can I ask you when each folder is executed, also does the scripts inside them must have .sh extension or not ?
I want to restart my systemui after boot complete, can you tell me if this script is ok ?
Code:
#!system/bin/sh
sleep 20
su
pkill -l TERM -f com.android.systemui
ps : the pkill command works fine after an "su" in terminal emulator
sorry for the offtopic !
Click to expand...
Click to collapse
So, second thing, @sheraro, I think you should delete the command su from your script because Magisk scripts are running as root anyway and if you issue su command it will start a shell with elevated privileges - an interactive shell, not what you want here, a sudo like command.. it works in the terminal because it is interactive but in the shell script if you start su it starts an interactive shell and it halts your script because it won't exit the shell you started.. and the next command will never run.. if you know what I mean.. but you don't need it anyway, because - as I mentioned - it is running as root anyway. +1: The syntax of the shebang is bad in your example, it is missing an exclamation mark. Can you re-test it like this:
Code:
#!/system/bin/sh
sleep 20
pkill -l TERM -f com.android.systemui
exit 0
.sh extension is not needed, the thing is: you have to set the correct permission in the config.sh like this:
Code:
set_permissions() {
# Default permissions, don't remove them
set_perm_recursive $MODPATH 0 0 0777 0777
[..omitted..]
Thing is: the files must have execute priv. and you can execute them like
Code:
$MODDIR/./desiredfilename
in the services.sh script.
Hope this helps.
crok.bic said:
.sh extension is not needed, the thing is: you have to set the correct permission in the config.sh like this:
Code:
set_permissions() {
# Default permissions, don't remove them
set_perm_recursive $MODPATH 0 0 0777 0777
[..omitted..]
Thing is: the files must have execute priv. and you can execute them like
Code:
$MODDIR/./desiredfilename
in the services.sh script.
Hope this helps.
Click to expand...
Click to collapse
I'm just pasting my script in service.d only, set permissions manually to 0777, corrected !#/system typo, removed su command, but no luck...
Where's services.sh and config.sh ?
sheraro said:
I'm just pasting my script in service.d only, set permissions manually to 0777, corrected !#/system typo, removed su command, but no luck...
Where's services.sh and config.sh ?
Click to expand...
Click to collapse
Reading your comment I think you are not developing a Magisk module, do you?
I do and this is why you have no idea where is config.sh, services.sh and the others I think.
If you just want to have some kind of "init.d script" support and run the script in your own phone *only* then your script should be in the folder /magisk/.core/service.d and it should have execute permission. That's all what you need - probably the sleep 20 is not enough, increase it to sleep 30 for instance.
If this is still not enough info I would suggest to read the Magisk documentation thoroughly (linked in post #4) and if you still stuck I suggest you to open your own thread, describe your problem thoroughly (what is your goal? what would you like to achive? how did you already try? what is happening but should not or not happening but you think it should happen? you know what I mean..) and ask the community. Probably you will be able to solve your issue in minutes/hours.
I changed it to sleep 100, same problem, you're right I should create a new thread for this.
I have a theme installed that mimics oreo style, but the systemUI is not themed until it's restarted, so I thought about a script executed after boot, anyway thanks for your help
It seems that sleep will delay the run of other modules' service.sh. is there any solution that will not affect other module?
nicorg3221 said:
It seems that sleep will delay the run of other modules' service.sh. is there any solution that will not affect other module?
Click to expand...
Click to collapse
I don't experience this behavior - what you described is the post-fs-data behavior.
I did the trick with a separate ("auxiliary") file and tried to explain how in post #5 but let me try again:
- created a file in the module's common folder (I gave the name `tweak`)
- this file starts with a shebang (it's a script..) and continues with a sleep 30 then comes my commands..
- then copied the file from the module to the Magisk module directory into /magisk/$MODDIR with the module file META-INF/com/google/android/update-binary (I added it to the copy section, manually.. I know, I know, it should work automagically anyway, but did not work and I was fed up with the coding, so hardcoded it.. sorry)
- I set the default file permission to 0777 in config.sh (yes, 0777, this is loose AF but works.. and I don't really care, the file contains code that can make the device *better* and has no suid bit set, so there is only little to no room to harm anything..)
- then I included a call in my module's common/service.sh like $MODDIR/./tweak to start my script
- when the tweak script starts it will start with the sleep 30 so implements the delay.. BUT!
- Because services.sh files from the modules are called parallelly by Magisk (by default, by it's nature, by it's code.. you got it) my module does not delays others - but still has the delay.
Hope this helps.
sheraro said:
I changed it to sleep 100, same problem, you're right I should create a new thread for this.
I have a theme installed that mimics oreo style, but the systemUI is not themed until it's restarted, so I thought about a script executed after boot, anyway thanks for your help
Click to expand...
Click to collapse
Pleased to help you - but honestly, if the only task you need is to kill and restart systemUI then I would do it via init.d script run by an app that mimics init.d scripting, or using a kernel that supports init.d scripts (if only you want to use that theme). It's just less complex for you I think, but honestly, a simple script file that has execute permission in /magisk/.core/services.d/ gives you 100% the same solution.
crok.bic said:
I don't experience this behavior - what you described is the post-fs-data behavior.
I did the trick with a separate ("auxiliary") file and tried to explain how in post #5 but let me try again:
- created a file in the module's common folder (I gave the name `tweak`)
- this file starts with a shebang (it's a script..) and continues with a sleep 30 then comes my commands..
- then copied the file from the module to the Magisk module directory into /magisk/$MODDIR with the module file META-INF/com/google/android/update-binary (I added it to the copy section, manually.. I know, I know, it should work automagically anyway, but did not work and I was fed up with the coding, so hardcoded it.. sorry)
- I set the default file permission to 0777 in config.sh (yes, 0777, this is loose AF but works.. and I don't really care, the file contains code that can make the device *better* and has no suid bit set, so there is only little to no room to harm anything..)
- then I included a call in my module's common/service.sh like $MODDIR/./tweak to start my script
- when the tweak script starts it will start with the sleep 30 so implements the delay.. BUT!
- Because services.sh files from the modules are called parallelly by Magisk (by default, by it's nature, by it's code.. you got it) my module does not delays others - but still has the delay.
Hope this helps.
Click to expand...
Click to collapse
I have my script in starting in .Core. Maybe that's the problem
nicorg3221 said:
I have my script in starting in .Core. Maybe that's the problem
Click to expand...
Click to collapse
..then it is in the wrong dir.. it is clearly described in the Magisk documentation.
I have researched a bit. I think you can use getprop sys.boot_completed to check if boot is completed. We should run init.d scripts after boot is completed instead of just wait for 30/100 seconds.
I place all my init.d scripts I want to run in /magisk/.core/service.d/init.d.
Then, I have a service.d script [exec_init_d.sh] in /magisk/.core/service.d. Magisk will run exec_init_d.sh when boot.
exec_init_d.sh will wait for sys.boot_completed and run all the files in /magisk/.core/service.d/init.d after boot completed
exec_init_d.sh
Code:
#!/system/bin/sh
# Please don't hardcode /magisk/modname/... ; instead, please use $MODDIR/...
# This will make your scripts compatible even if Magisk change its mount point in the future
MODDIR=${0%/*}
# This script will be executed in late_start service mode
# More info in the main Magisk thread
if [ "$1" != "1" ]; then
$0 1 &
log -p i -t Magisk "start new instance to let Magisk boot stages proceed"
exit
fi
#param
RUNLOG=0
RETRY_INTERVAL=5 #in seconds
MAX_RETRY=60
EXEC_WAIT=3 #in seconds
INIT_D_DIR=$MODDIR/init.d
LOG_PATH=$MODDIR/debug.log
#init
retry=${MAX_RETRY}
#wait for boot completed
log -p i -t Magisk "wait for boot completed"
while (("$retry" > "0")) && [ "$(getprop sys.boot_completed)" != "1" ]; do
sleep ${RETRY_INTERVAL}
((retry--))
done
if (("$retry" == "0")); then
log -p i -t Magisk "boot not completed within maximum number of retry"
else
log -p i -t Magisk "boot completed"
fi
sleep ${EXEC_WAIT}
log -p i -t Magisk "init.d execution started from ${INIT_D_DIR}"
if (("${RUNLOG}" == "1")); then
/data/magisk/busybox run-parts $INIT_D_DIR &> $LOG_PATH
log -p i -t Magisk "init.d execution output written to $LOG_PATH"
else
/data/magisk/busybox run-parts $INIT_D_DIR
fi
log -p i -t Magisk "init.d execution completed"

[WORKAROUND] - Magisk Not Installed - [Module]

I have Magisk v18.1 installed on my OG Pixel running PixelDust ROM and noticed every so often it loses root access. When entering the Magisk Manager app it also shows Magisk Not Installed. I did some investigating and found that magiskd (magisk daemon) gets terminated at some point randomly. Further testing revealed I could restart it manually by issuing "magisk --daemon" via SSH/ADB root shell.
I wrote a simple module to keep the daemon running and haven't noticed the "Magisk Not Found" error since. The module is just a simple bash script executed as service on boot that checks every minute for the daemon and runs the "magisk --daemon" command as root if not running. I am just posting it here to see if it can help anyone else who's root access disappears randomly on v17-19.3.
Please be aware that this is my first module ever. It was also originally started via an init.d script instead of the service hook in magisk, though it should work exactly the same. I have also noticed it is not possible for my module to restart magiskd yet if it was killed manually by the user.
GIt Repo:
https://github.com/Geofferey/mgkdhelper
Magisk Repo Submission:
https://github.com/Magisk-Modules-Repo/submission/issues/404
Release:
UNINSTALL INITIAL v1.0.0 RELEASE BEFORE INSTALL!!!
If you fail to do so you will have the old version and current version running at same time.
Download:
Current Release v2.1.0
Major thanks to @jcmm11 & @char101 whose contributions are now officially included in this module.
I just wanna say God bless you for this module, my man. I was frustratingly having my Magisk daemon getting killed 2-3 times a day On my LG V20. Since installing your module for the past 4 days ive yet to encounter such an issue. I greatly appreciate you coming up w/a solution to a problem that was frustrating me to the max
Geofferey said:
I wrote a simple module to keep the daemon running and haven't noticed the "Magisk Not Found" error since.
Click to expand...
Click to collapse
Thanks for that module. Very good idea and it's working perfectly fine. :good:
Hi,
There is no /data/local/run directory by default on my phone (OP6 Pie). So I suggest that either you create it first or simply uses /data/local/tmp to store the pid. Also creating the directory first might be a good idea. If you add -q to the grep command there is no need to redirect the output.
Code:
#!/system/xbin/bash
PIDFILE=/data/local/tmp/magiskd-helper.pid
LOGFILE=/data/local/tmp/magiskd-helper.log
is_magisk_running() {
ps -a | grep -q [m]agiskd
}
if [ ! -d /data/local/tmp ]; then
mkdir -p /data/local/tmp
fi
if [ -f $PIDFILE ]; then
kill -9 `cat $PIDFILE`
fi
echo $$ > $PIDFILE
RETRIES=0
while true; do
sleep 60
if ! is_magisk_running; then
echo `date` >> $LOGFILE
echo 'Magisk daemon appears to have crashed' >> $LOGFILE
echo 'Restarting magiskd...' >> $LOGFILE
/sbin/magisk --daemon
if is_magisk_running; then
echo 'Success!' >> $LOGFILE
RETRIES=0
else
echo 'Failure!' >> $LOGFILE
((++RETRIES))
if (( $RETRIES > 10 )); then
echo 'Giving up' >> $LOGFILE
break
fi
fi
echo >> $LOGFILE
fi
done
When first run, /system/bin/ps is linked to magisk builtin busybox, which don't have the -u option
Code:
ps: invalid option -- u
BusyBox v1.30.1-topjohnwu (2019-04-30 01:01:15 EDT) multi-call binary.
Usage: ps [-o COL1,COL2=HEADER] [-T]
Show list of processes
-o COL1,COL2=HEADER Select columns for display
-T Show threads
char101 said:
When first run, /system/bin/ps is linked to magisk builtin busybox, which don't have the -u option
Code:
ps: invalid option -- u
BusyBox v1.30.1-topjohnwu (2019-04-30 01:01:15 EDT) multi-call binary.
Usage: ps [-o COL1,COL2=HEADER] [-T]
Show list of processes
-o COL1,COL2=HEADER Select columns for display
-T Show threads
Click to expand...
Click to collapse
Try again after having install the 'Busybox for NDK' Magisk module (from osm0sis), maybe that the -u arg for ps command will works i ddon't remember me having testing it recently so idk if it will works but i think yeah
I have the GNU coreutils module installed so it is not the problem.
Also the original module redirect stderr to /dev/null so unless you modify it you won't see the error like I posted before.
My modifications
service.sh
Code:
#!/system/bin/sh
# Do NOT assume where your module will be located.
# ALWAYS use $MODDIR if you need to know where this script
# and module is placed.
# This will make sure your module will still work
# if Magisk change its mount point in the future
MODDIR=${0%/*}
# This script will be executed in late_start service mode
$MODDIR/common/magisk-monitor > /data/local/tmp/magisk-monitor.log 2>&1 &
magisk-monitor
Code:
#!/system/bin/sh
is_magisk_running() {
ps -A | grep -q [m]agiskd
}
sleep 300
echo `date`
echo 'magisk-monitor running'
echo
RETRIES=0
while true; do
sleep 60
if ! is_magisk_running; then
echo `date`
echo 'Magisk daemon appears to have crashed'
echo 'Restarting magiskd...'
/sbin/magisk --daemon
if is_magisk_running; then
echo 'Success!'
RETRIES=0
else
echo 'Failure!'
((++RETRIES))
if (( $RETRIES > 10 )); then
echo 'Giving up'
break
fi
fi
echo
fi
done
Rom said:
Try again after having install the 'Busybox for NDK' Magisk module (from osm0sis), maybe that the -u arg for ps command will works i ddon't remember me having testing it recently so idk if it will works but i think yeah
Click to expand...
Click to collapse
I doubt it... From busybox.net:
ps
Report process status
Options:
-o col1,col2=header Select columns for display
-T Show threads
Click to expand...
Click to collapse
It is better to just use 'ps -A' which will work on busybox ps and coreutils ps.
Didgeridoohan said:
I doubt it... From busybox.net:
Click to expand...
Click to collapse
I'm agree with u, but it was already happen for me that some other args works too, i had never know why.
I came across your module while looking for the same issue affecting many users on different devices (although it seems to be affecting Pie only). Magisk GitHub is also full of reports by people losing root and solving with a reboot. I don't know how impactful it is on the battery since it checks for Magisk every 60 seconds (I have just installed it) but so far your module is the only blessing we can get to avoid rebooting once/twice per day. I think you should definitely submit your module to the official repository!
P.s i had to create /data/local/run first for the pid
@Geoffrey another quick correction: in my case on MIUI 10 based on Pie, ps -a does not show the same output as ps -A. So I had to replace the -a in your script with an upper case A.
char101 said:
It is better to just use 'ps -A' which will work on busybox ps and coreutils ps.
Click to expand...
Click to collapse
Coreutils doesn't have a ps applet. If you want to use -u just use the full path /system/bin/ps to force the toybox applet.
@Geoffrey
First of all nice workaround. I did some cleanup and a few modifications if you want to post it to the Magisk repository (and I think you should).
Changed over to the current template.
Removed all the PID stuff, it's really not needed.
Replaced ps -a -u with pgrep. That eliminates any busybox vs toybox issues (at least the way it's being used here)
Removed bash. There's nothing here that requires a bash shell as opposed to the default shell.
Moved the script to it's own directory instead of xbin. Not all phones have xbin, and trying to use it on those that don't is problematic. Plus there's no reason the script needs to be in the PATH.
Added nohup to the script startup command in service.sh
Also always create the log file, with a "started on" line in it. That at least gives an indication that the script started.
So what we're left with.
mgkd-helper (in a script directory)
Code:
#!/system/bin/sh
LOGFILE=/data/local/tmp/magiskd-helper.log
rm -f $LOGFILE
echo "Started " $(date) >> $LOGFILE
echo "-----------------------------" >> $LOGFILE
echo >> $LOGFILE
while true; do
sleep 60
if ! pgrep magiskd >/dev/null; then
echo $(date) >> $LOGFILE
echo "Magisk daemon appears to have crashed" >> $LOGFILE
echo "Restarting magiskd..." >> $LOGFILE
if magisk --daemon; then
echo "success!" >> $LOGFILE
else
echo "failure!" >> $LOGFILE
fi
echo >> $LOGFILE
fi
done
service.sh
Code:
#!/system/bin/sh
# Do NOT assume where your module will be located.
# ALWAYS use $MODDIR if you need to know where this script
# and module is placed.
# This will make sure your module will still work
# if Magisk change its mount point in the future
MODDIR=${0%/*}
# This script will be executed in late_start service mode
#Magisk Daemon Helper
# Copyright (C) 2019 Geofferey @ XDA
# License: GPL V3+
nohup $MODDIR/script/mgkd-helper > /dev/null &
If you do decide to place it in the repository you need to do something with README.md
You should also replace META-INF/com/google/android/update-binary with the attached version. The included version is for standalone installs. Repository versions should use the alternate one. (Remove the ".txt")
Last note: tested this and it does work. I killed the running magiskd and a new one was started, with the appropriate log entry created
I wasn't able to start magiskd with "magisk -- daemon" via adb. It always says "No daemon found" instead of starting it. I seem to have lost root with the original script and I had to restart again. Any idea? I just enabled root via adb in Magisk. Not sure if that was the issue that I couldn't restart it.
And it seems like magiskd is killed in OxygenOS 9.0.5 on my OnePlus 6. Not sure if it is due to out of memory reasons but I can't get any logcat as I don't have root. Super annoying.
Will this be added to the magisk module repository? If it is there I couldn't find it. I do know there are links and a revision at the end of the thread by @jcmm11. I don't need the module, just curious if the revision will be put there eventually. I have had others with that problem that I have helped.
Thanks
martyfender said:
Will this be added to the magisk module repository? If it is there I couldn't find it. I do know there are links and a revision at the end of the thread by @jcmm11. I don't need the module, just curious if the revision will be put there eventually. I have had others with that problem that I have helped.
Thanks
Click to expand...
Click to collapse
I think it should be but it's up to @Geoffrey. It's his module. I cleaned it up a bit that's all. Most of the work is done. Biggest thing left to do is modify README.md
jcmm11 said:
@Geoffrey
First of all nice workaround. I did some cleanup and a few modifications if you want to post it to the Magisk repository (and I think you should).
Changed over to the current template.
Removed all the PID stuff, it's really not needed.
Replaced ps -a -u with pgrep. That eliminates any busybox vs toybox issues (at least the way it's being used here)
Removed bash. There's nothing here that requires a bash shell as opposed to the default shell.
Moved the script to it's own directory instead of xbin. Not all phones have xbin, and trying to use it on those that don't is problematic. Plus there's no reason the script needs to be in the PATH.
Added nohup to the script startup command in service.sh
Also always create the log file, with a "started on" line in it. That at least gives an indication that the script started.
So what we're left with.
mgkd-helper (in a script directory)
service.sh
If you do decide to place it in the repository you need to do something with README.md
You should also replace META-INF/com/google/android/update-binary with the attached version. The included version is for standalone installs. Repository versions should use the alternate one. (Remove the ".txt")
Last note: tested this and it does work. I killed the running magiskd and a new one was started, with the appropriate log entry created
Click to expand...
Click to collapse
Should we directly flash zip in twrp recovery
kryshnakishore said:
Should we directly flash zip in twrp recovery
Click to expand...
Click to collapse
You can flash it in recovery or via Magisk Manager, modules section, big + button at bottom of screen.
I've been looking for a solution to this since v17 ... started happening on 17, kept happening on 18, is even worse now on v19 ... :-/

creating my 1st module: but service.sh never run

Magisk v19.3 on lineageos 16.0 for wt86047
trying to create my first module, no files to replace, just one task: run a remove.sh script
I put following two lines in ./common/service.sh , but there's no file created after boot , seems the service.sh itself never be run at all.
echo -e "\n------------${MODPATH}----------------------------" >> /sdcard/s.txt >&1
sh ./remove.sh
LATESTARTSERVICE=true in ./install.sh --YES
./META-INF/com/google/android/update-binary updated --YES
./module.prop edited --YES
the module installed with no error --YES
manual run remove.sh successfully in terminal after reboot --YES
called from service.sh --NO
need help, THANK YOU!
attached remove.sh
Code:
#!/system/bin/sh
DIRFILE="/sdcard/dir"
if [ -f "$USRFILE" ];then
while IFS= read -r LINE
do
if [ -n "${LINE}" ];then
...
...
fi
I haven't looked at what might be your issue, but you don't need a module for that... Just place your remove.sh script in /data/adb/service.d and give it execution permission.
Didgeridoohan said:
I haven't looked at what might be your issue, but you don't need a module for that... Just place your remove.sh script in /data/adb/service.d and give it execution permission.
Click to expand...
Click to collapse
thanks. but it doesn't work either.
When I manually run the script from terminal, it prompt 'Permission denied.'
But it works after execute 'su' first.
Is this the reason? But how could I authorise root right to the script since it doesn't pop dialogbox at all.
Again, I haven't looked at your script at all, but...
Any scripts run by Magisk at boot will run with superuser permission. That's not your issue...
Might be that the script has to run after boot is completed (if it works while booted but not during boot). You can look for the sys.boot_completed and when it's changed to 1 you can let the script execute.
I use this code in my modules, if it can help
Code:
_SLEEPBOOT=60
# ...
RETRY_INTERVAL=${_SLEEPBOOT} #in seconds
MAX_RETRY=30
retry=${MAX_RETRY}
while (("$retry" > "0")) && [ "$(getprop sys.boot_completed)" != "1" ]; do
sleep ${RETRY_INTERVAL}
((retry--))
done
Didgeridoohan said:
Again, I haven't looked at your script at all, but...
Any scripts run by Magisk at boot will run with superuser permission. That's not your issue...
Might be that the script has to run after boot is completed (if it works while booted but not during boot). You can look for the sys.boot_completed and when it's changed to 1 you can let the script execute.
Click to expand...
Click to collapse
Code:
# Wait for boot to complete
until [ "$(getprop sys.boot_completed)" ]
do
sleep 2
done
insert this code to script but still not work...
after all, found the solution:
don't use '/sdcard/, use '/storage/emulated/0/' instead, don't know why
funnypc said:
Code:
# Wait for boot to complete
until [ "$(getprop sys.boot_completed)" ]
do
sleep 2
done
insert this code to script but still not work...
after all, found the solution:
don't use '/sdcard/, use '/storage/emulated/0/' instead, don't know why
Click to expand...
Click to collapse
Might have worked if you had checked for sys.boot_completed = 1.
But yeah, /sdcard isn't available during boot. To be even more sure it'll work you could use /data/media/0 instead. That's always available (as long as /data is accessible).
Didgeridoohan said:
Might have worked if you had checked for sys.boot_completed = 1.
But yeah, /sdcard isn't available during boot. To be even more sure it'll work you could use /data/media/0 instead. That's always available (as long as /data is accessible).
Click to expand...
Click to collapse
though the script can work alone , I still want make it a module so that could install/disable easier with magisk gui than terminal.
currently I'm add a 'bypass' mode while script load, if volume key pressed repeatly. (like xposed does) but the code can only work after unlock, it seems the getevent can't work after system reboot, before keyguard unlocked. any workaround? thx!
Code:
#!/system/bin/sh
KEYSTRING="KEY_VOLUME"
KEYREPEAT=1
KEYCOUNTS=0
until [ "$(getprop sys.boot_completed)" ]
do
sleep 2
done
setenforce Permissive
echo 300 > /sys/class/timed_output/vibrator/enable
sleep 0.3
for i in `seq 1 4`;
do
EVENT=$(timeout 1 getevent -l -q -c 1)
RESULT=`echo $EVENT | grep -c $KEYSTRING`
input keyevent mouse
if [ "$RESULT" -gt 0 ] ;then
KEYCOUNTS=`expr $KEYCOUNTS + $RESULT`
echo 100 > /sys/class/timed_output/vibrator/enable
fi
done
if [ "$KEYCOUNTS" -gt "$KEYREPEAT" ] ;then
echo 1000 > /sys/class/timed_output/vibrator/enable
fi
Simple, just put your code in the service.sh file of the module instead of a separate script file...
Didgeridoohan said:
Simple, just put your code in the service.sh file of the module instead of a separate script file...
Click to expand...
Click to collapse
can't work. so I put the keypress detection part in a standalone script for debug. just script in service.d folder, not pack to module yet.
if I run the script manually in terminal after keyguard unlocked, everything works as I want
but not when keyguard locked status just after reboot.
funnypc said:
can't work. so I put the keypress detection part in a standalone script for debug. just script in service.d folder, not pack to module yet.
if I run the script manually in terminal after keyguard unlocked, everything works as I want
but not when keyguard locked status just after reboot.
Click to expand...
Click to collapse
I mean the code from your remove.sh file, not the key detecting stuff... That way you can disable the module from the Manager and also from TWRP (or other custom recovery) by placing a disable file in the module directory or enabling Magisk Core Only Mode by placing a .disable_magisk file in /cache.

Categories

Resources