Another option here is to create a cronjob that alters the OOM score adjustment per process using the following on a periodic interval:
pgrep -f "processName" | while read PID; do echo "-1000" >/proc/$PID/oom_score_adj; done
I use this method to prevent the killing of lipstick, ofono and signal under any circumstances.
Another option, for processes which are daemons, one may alter the systemd unit (or craft one if it does not exist) to include the following under the Service stanza:
OOMScoreAdjust=-1000
This is the method I use to start and run s1p at all times and prevent any accidental killings.
Example: /etc/systemd/system/s1p.service
[Unit]
Description=S1P Service
Wants=network.target
After=syslog.target network-online.target
[Service]
Type=simple
User=root
OOMScoreAdjust=-1000
Environment="DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/100000/dbus/user_bus_socket"
ExecStart=/bin/su - defaultuser -c "/bin/bash /usr/share/harbour-s1p/sipBabysitter.sh"
ExecStop=/bin/su - root -c "/bin/ps aux | /bin/grep s1p | /bin/grep -v grep | /bin/awk '{print $1}' | /usr/bin/xargs /bin/kill -9"
Restart=always
RestartSec=10
KillMode=process
[Install]
WantedBy=multi-user.target`
Mined you it is possible to start any SFOs app this way- just create a wrapper using the following example and the service example above. It is critical to include the DBUS environment lines. Don’t ignore those. This babysitter script also implements hanging process cleanup on failure.
Example: /usr/share/harbour-s1p/sipBabysitter.sh
#!/bin/bash
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/100000/dbus/user_bus_socket
checkInterval=30
function StartProcesses {
echo "s1p sipBabysitter - Starting main s1p processes..."
/usr/bin/invoker -o --type=generic --single-instance s1p --qml harbour-s1p &
echo "Waiting 30s before polling for s1p processes..."
sleep 30
}
function KillProcesses {
echo "s1p sipBabysitter - Doing process cleanup..."
/bin/ps aux | /bin/grep s1p | /bin/grep -v grep | /bin/awk '{print $1}' | /usr/bin/xargs /bin/kill -9
}
function CheckProcesses {
echo "s1p babySitter - Checking processess..."
testSipServer=$(ps aux | grep "/usr/bin/s1p" | grep -v grep | wc -l)
testLauncher=$(ps aux | grep "/usr/bin/invoker" | grep "s1p --qml harbour-s1p" | grep -v grep | wc -l)
testUi=$(ps aux | grep "sailfish-qml harbour-s1p" | grep -v grep | wc -l)
if [ $testSipServer -eq 1 ] && [ $testLauncher -eq 1 ] && [ $testUi -eq 1 ]
then
return 0
else
return 1
fi
}
StartProcesses
CheckProcesses
resValue=$?
while [ $resValue -eq 0 ]
do
echo "s1p babySitter - Process Check result: OK"
sleep $checkInterval
CheckProcesses
resValue=$?
done
echo "s1p babySitter - Process Check result: Failed"
KillProcesses
exit 1