0

I have a shell script that gets updates from github and then runs the code that it retrieved. it is located at /home/me/Desktop/refreshCode.sh

-- refreshCode.sh --

#!/bin/bash

cd /home/me/src/ProductionMonitor
sudo /usr/bin git -C /home/me/src/ProductionMonitor pull
sudo cp /home/me/src/ProductionMonitor/* /home/me/Desktop/Production
cd /home/me/Desktop/Production
sudo /usr/bin/python3 prodmain.py >> logfile.data

I know that the shell can launch and runs as expected manually. It opens up the tkinter window and I can interact with the screen.

However I cannot seem to get anything to launch correctly.

I have tried setting up a crontab for @reboot and was not successful. It never showed the ui

I set up a Systemd service as such.

-- prodmon.service --

[Unit]
Description=Service to run production monitor
After=multi-user.target

[Service]
Type=forking
ExecStart=/home/me/Desktop/refreshCode.sh
User=caleb
Group=caleb
WorkingDirectory=/home/me/Desktop/Production/
PIDFile=/var/run/prodmon.pid

[Install]
WantedBy=multi-user.target

Checking the status of the service after boot, it says that it is running. however the tkinter UI never shows up.

  • 3
    Instead of sudo /usr/bin git... you probably mean sudo /usr/bin/git... What do you mean with "It never showed the ui"? A program run by cron should never show a UI. It should do some work and write messages to a logfile or to syslog. If you want to run a program with a graphical UI, see askubuntu.com/q/37957 – Bodo Mar 5 at 17:52
  • 4
    Why on Earth do you require superuser access to write files into your own home directory? – JdeBP Mar 5 at 17:53
  • @JdeBP most of the reason you see an overuse of the sudo command is because I am pretty new to Linux. I don't want to sit and fight permissions right now so I sudo everything I can. I know its terrible practice and Ive been warned by many linux users that I need to correct it – caleb baker Mar 5 at 19:16
  • The thing is that using sudo without thinking twice is the reason why you have to "fight permissions". It leads to all kinds of files being owned by root when they shouldn't be, requiring another sudo to access them and so on. Better chown everything in your home back to your user and stop using sudo unless absolutely necessary. – TooTea Mar 5 at 19:21
1

You should probably not sudo all the stuff; all things are under your own directory.

The main point of your question is, that your script does not know where to display the window. Try adding

echo "DISPLAY=$DISPLAY" >> logfile.data

You will probably see

DISPLAY=

in `logfile.data. Furthermore, if you use:

/usr/bin/python3 prodmain.py >> logfile.data 2>/tmp/errorfile

you will probably see a /tmp/errorfile with something like:

prodmain: Xt error: Can't open display: 
prodmain: DISPLAY is not set

So, that is the reason why it does not display at boot.

Now how to solve it: that depends a lot on what you want.You can start the program from ~/.xinitrc when you log-in to the graphical environment. You can cut the job into two parts: doing the git and cp at boot, and the prodmain from the .xinitrc.

  • I am unfamiliar with ~/.xinitrc Is there something that I need to get or do I simply create the file. Ps you are correct about the display part – caleb baker Mar 5 at 19:19
  • .xinitrc runs commands when an X11 session (graphical interface for most Linuces) starts. Do a cat ~/.xinitrc to see what is done there. – Ljm Dullaart Mar 6 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.