FORUMS
Remove All Ads from XDA

[WORKAROUND] - Magisk Not Installed - [Module]

160 posts
Thanks Meter: 140
 
Post Reply Email Thread
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-Re...ion/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.
Attached Files
File Type: zip magiskd-helper.zip - [Click for QR Code] (1.06 MB, 1180 views)
File Type: zip mgkdhelper-v1.0.1.zip - [Click for QR Code] (6.4 KB, 158 views)
File Type: zip mgkdhelper-v2.0.2.zip - [Click for QR Code] (7.0 KB, 190 views)
File Type: zip mgkdhelper-v2.1.0.zip - [Click for QR Code] (7.4 KB, 1548 views)
The Following 18 Users Say Thank You to Geofferey For This Useful Post: [ View ] Gift Geofferey Ad-Free
 
 
31st March 2019, 01:05 AM |#2  
Junior Member
Thanks Meter: 2
 
More
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
The Following User Says Thank You to Brian23MAC For This Useful Post: [ View ] Gift Brian23MAC Ad-Free
26th April 2019, 10:17 AM |#3  
xXx's Avatar
Senior Member
Flag Munich
Thanks Meter: 15,588
 
Donate to Me
More
Quote:
Originally Posted by Geofferey

I wrote a simple module to keep the daemon running and haven't noticed the "Magisk Not Found" error since.

Thanks for that module. Very good idea and it's working perfectly fine.
The Following User Says Thank You to xXx For This Useful Post: [ View ] Gift xXx Ad-Free
21st May 2019, 02:01 PM |#4  
Senior Member
Thanks Meter: 77
 
More
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
The Following User Says Thank You to char101 For This Useful Post: [ View ] Gift char101 Ad-Free
22nd May 2019, 03:55 AM |#5  
Senior Member
Thanks Meter: 77
 
More
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
The Following User Says Thank You to char101 For This Useful Post: [ View ] Gift char101 Ad-Free
22nd May 2019, 05:57 AM |#6  
Rom's Avatar
Senior Member
Flag Lyon
Thanks Meter: 1,021
 
Donate to Me
More
Quote:
Originally Posted by char101

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

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
The Following User Says Thank You to Rom For This Useful Post: [ View ] Gift Rom Ad-Free
22nd May 2019, 06:17 AM |#7  
Senior Member
Thanks Meter: 77
 
More
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
22nd May 2019, 06:18 AM |#8  
Didgeridoohan's Avatar
Recognized Contributor
Flag Gothenburg
Thanks Meter: 7,091
 
Donate to Me
More
Quote:
Originally Posted by Rom

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 doubt it... From busybox.net:
Quote:

ps

Report process status

Options:

-o col1,col2=header Select columns for display
-T Show threads

22nd May 2019, 06:25 AM |#9  
Senior Member
Thanks Meter: 77
 
More
It is better to just use 'ps -A' which will work on busybox ps and coreutils ps.
22nd May 2019, 06:59 AM |#10  
Rom's Avatar
Senior Member
Flag Lyon
Thanks Meter: 1,021
 
Donate to Me
More
Quote:
Originally Posted by Didgeridoohan

I doubt it... From busybox.net:

I'm agree with u, but it was already happen for me that some other args works too, i had never know why.
27th May 2019, 03:03 AM |#11  
thunderteaser's Avatar
Senior Member
Flag Aversa
Thanks Meter: 272
 
More
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
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes