0

I have been researching how to run a minecraft server from the raspberry pi, so I finally got it set up!

So I thought to myself, I can go one set further... So I have been working on making a python script that runs the server whenever a button IRL is pressed. It worked very well until it said:

An exception occurred processing Appender File org.apache.logging.log4j.core.appender.AppenderLoggingException
Error writing to RandomAccessFile logs/latest.log

my code is as follows:

import RPi.GPIO as GPIO
import os
import time

GPIO.setmode(GPIO.BOARD)

GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

try:
while True:
    #Test to see if the button has been pressed
    if (GPIO.input(11) == 1):
        print ("Downloading Server to clear corruption...")
        #download specified version
        os.system("wget https://s3.amazonaws.com/Minecraft.Download/versions/1.8.1/minecraft_server.1.8.1.jar")
        print ("Moving file...")
        os.system("mv /home/pi/minecraft_server.1.8.1.jar /home/pi/Server/server.jar")
        print ("Finished")
        print ("Starting Server")
        #start server
        os.system("java -Xms1024M -Xms1024M -jar /home/pi/Server/server.jar nogui")
        print ("Server Stopped!")
        time.sleep(2)

except KeyboardInterrupt:
    GPIO.cleanup()

When I run the server as

cd Server
java -Xms1024M -Xms1024M -jar server.jar nogui

It works perfectly!

I think the problem is that when I run the python script, it does not have enough authority so it cannot edit files.

I launch the script as

sudo python controller.py

My question is; is there anyway on making a python script run a terminal command with the power of superuser?

2
  • Use the sudo access modifier. Commented Mar 2, 2015 at 21:29
  • Where should I use it though? Commented Mar 3, 2015 at 7:08

1 Answer 1

2

To answer the stated question at the bottom of your question, you can make the Python script run a terminal command by prepending sudo to the command itself.

 os.system("sudo java -Xms1024M -Xms1024M -jar /home/pi/Server/server.jar nogui")
Sign up to request clarification or add additional context in comments.

1 Comment

@James Burnell, Please accept the answer if it resolves your question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.