-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom frc kill script to work around jvm bug (#699)
- Loading branch information
Showing
6 changed files
with
96 additions
and
10 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
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
37 changes: 37 additions & 0 deletions
37
src/main/java/edu/wpi/first/gradlerio/deploy/roborio/FRCProgramKillArtifact.java
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package edu.wpi.first.gradlerio.deploy.roborio; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
import javax.inject.Inject; | ||
|
||
import edu.wpi.first.deployutils.deploy.artifact.AbstractArtifact; | ||
import edu.wpi.first.deployutils.deploy.context.DeployContext; | ||
import edu.wpi.first.gradlerio.deploy.DeployStage; | ||
import edu.wpi.first.gradlerio.deploy.StagedDeployTarget; | ||
import edu.wpi.first.gradlerio.wpi.dependencies.tools.ToolInstallTask; | ||
|
||
public class FRCProgramKillArtifact extends AbstractArtifact { | ||
|
||
@Inject | ||
public FRCProgramKillArtifact(String name, StagedDeployTarget target) { | ||
super(name, target); | ||
|
||
target.setDeployStage(this, DeployStage.ProgramKill); | ||
|
||
|
||
} | ||
|
||
@Override | ||
public void deploy(DeployContext ctx) { | ||
ctx.getLogger().log(" Deploying new frcKillRobot script"); | ||
try (InputStream it = ToolInstallTask.class.getResourceAsStream("/frcKillRobot.sh")) { | ||
ctx.put(it, "/usr/local/frc/bin/frcKillRobot.sh.tmp"); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
ctx.execute("mv /usr/local/frc/bin/frcKillRobot.sh.tmp /usr/local/frc/bin/frcKillRobot.sh && chmod +x /usr/local/frc/bin/frcKillRobot.sh"); | ||
ctx.execute("sync"); | ||
ctx.execute(". /etc/profile.d/natinst-path.sh; /usr/local/frc/bin/frcKillRobot.sh -t -r 2> /dev/null"); | ||
} | ||
} |
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
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
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
FRC_PID_FILE=/var/run/natinst/FRC_UserProgram.pid | ||
|
||
usage() | ||
{ | ||
cat >&2 <<EOF | ||
Usage: ${0##*/} [-r] [-t] | ||
-r Restart the lvrt process | ||
-t Configure lvrt to start a text-based program | ||
EOF | ||
exit 1 | ||
} | ||
|
||
while getopts "rt" Option | ||
do | ||
case $Option in | ||
r) RESTART=yes;; | ||
t) TEXT_BASED_PROGRAM=yes;; | ||
*) usage;; | ||
esac | ||
done | ||
|
||
|
||
if [ "$TEXT_BASED_PROGRAM" = yes ]; then | ||
/usr/local/frc/bin/frcEnableTBLStartupApp.sh | ||
if [ "$RESTART" = yes ]; then | ||
nirtcfg --file /etc/natinst/share/lvrt.conf --set section=LVRT,token=RTTarget.LaunchAppAtBoot,value=True | ||
else | ||
nirtcfg --file /etc/natinst/share/lvrt.conf --set section=LVRT,token=RTTarget.LaunchAppAtBoot,value=False | ||
fi | ||
fi | ||
|
||
printf "%s - Killing robot code in frcKillRobot.sh\n" "`date`" | FRC_ConsoleTee | ||
|
||
if [ -e $FRC_PID_FILE ]; then | ||
DAEMON_PID=`cat $FRC_PID_FILE` | ||
if [ -e /proc/$DAEMON_PID ]; then | ||
PGROUP=`ps -o pid,pgid,comm | grep $DAEMON_PID | awk -v N=2 '{print $N}'` | ||
kill -term -- -$PGROUP | ||
sleep 1 | ||
kill -9 -- -$PGROUP | ||
fi | ||
rm -f $FRC_PID_FILE | ||
fi | ||
|
||
if [ "$RESTART" = yes ]; then | ||
RT_STARTUP_DISABLED=`nirtcfg --get section=SYSTEMSETTINGS,token=NoApp.enabled,value=false | tr "[:upper:]" "[:lower:]"` | ||
if [ "$RT_STARTUP_DISABLED" = false ]; then | ||
killall lvrt | ||
else | ||
/usr/local/frc/bin/frcRunRobot.sh & | ||
fi | ||
fi |