1

I am working on a Linux Debian server (AWS EC2) and I have a software that needs to run in a graphical environment.

If I start it manually (by typing ./program.sh in its directory) it is working fine: i can switch to a vncviewer window (its a cloud server that i am controlling remotely) i can see the program starting. the $DISPLAY value is set at boot time to :1.0

However if i try to have my program.sh to be run at boot time by creating a init.d script, I can see nothing happening in the graphical environment.

I have tried to read the log of my program but I couldnt find anything conclusive.

I think there is a problem either with the DISPLAY variable or with the xhosts permission, but because the soft I am running is a bit intricated (with login credentials etc) , it is tough for me to find the problem

That's why I would like to resort to creating a simple "hello_world.sh" script that would just open a simple window in the graphical env, to test what happens when starting it manually and with boot start.

Can anyone give me such a script? Its functionality should basically be: type ./hello_world.sh in a shell -> see a window opening in the graphical environment. The purpose would be to test how that simple script behave if i create an init.d startup script for it.


The detail of my current non-working init.d file is:

#!/bin/sh
### BEGIN INIT INFO
# Provides:          IBController
# Required-Start:    $remote_fs $syslog +vncserver
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start daemon at boot time
# Description:       Enable service provided by daemon.
### END INIT INFO

dir="/opt/IBController"
cmd="./IBControllerGatewayStart.sh"
user="depot"

name=`basename $0`
pid_file="/var/run/$name.pid"
stdout_log="/var/log/$name.log"
stderr_log="/var/log/$name.err"

get_pid() {
    cat "$pid_file"
}

is_running() {
    [ -f "$pid_file" ] && ps -p `get_pid` > /dev/null 2>&1
}

case "$1" in
    start)
    if is_running; then
        echo "Already started"
    else
        echo "Starting $name"
        xhost local:depot
    export DISPLAY=:2.0
        cd "$dir"
        if [ -z "$user" ]; then
            sudo $cmd >> "$stdout_log" 2>> "$stderr_log" &
        else
            sudo -u "$user" $cmd >> "$stdout_log" 2>> "$stderr_log" &
        fi
        echo $! > "$pid_file"
        if ! is_running; then
            echo "Unable to start, see $stdout_log and $stderr_log"
            exit 1
        fi
    fi
    ;;
    stop)
    if is_running; then
        echo -n "Stopping $name.."
        kill `get_pid`
        for i in 1 2 3 4 5 6 7 8 9 10
        # for i in `seq 10`
        do
            if ! is_running; then
                break
            fi

            echo -n "."
            sleep 1
        done
        echo

        if is_running; then
            echo "Not stopped; may still be shutting down or shutdown may have failed"
            exit 1
        else
            echo "Stopped"
            if [ -f "$pid_file" ]; then
                rm "$pid_file"
            fi
        fi
    else
        echo "Not running"
    fi
    ;;
    restart)
    $0 stop
    if is_running; then
        echo "Unable to stop, will not attempt to start"
        exit 1
    fi
    $0 start
    ;;
    status)
    if is_running; then
        echo "Running"
    else
        echo "Stopped"
        exit 1
    fi
    ;;
    *)
    echo "Usage: $0 {start|stop|restart|status}"
    exit 1
    ;;
esac

exit 0
  • This wouldn't work with an init.d script as sysVInit doesn't have a graphical display when it starts the background processes. – Raman Sailopal Nov 17 '17 at 13:54
  • @Raman Sailopal I have a vnc sevrer that is also started at boot – jim basquiat Nov 17 '17 at 14:03
  • Please attach the init.d you created. – Arpit Agarwal Nov 17 '17 at 17:04
  • @Arpit Agarwal Just added it – jim basquiat Nov 17 '17 at 20:36
0

Desktop Environment loads after the user has logged in. So, init.d won't work because there will be no Xserver running.

Before trying below workaround you will also have to configure Debian to autologin the specified user so that GUI loads.

Create a program.desktop file inside this directory /home/$user/.config/autostart/. Make directory if not exists.

program.desktop

[Desktop Entry]
Type=Application
Exec=program.sh
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name=Porgram
Comment=Program Description

There are some related questions, have a look at them also.

  • thx for your reply. This is the soft i am trying to autostart: dimon.ca/… (you can skip to the section: "Make it all startup on boot!"). How do you explain it works in that example? – jim basquiat Nov 17 '17 at 16:59
  • I also have tried simply starting the soft using systemctl start program i.e. after the boot, still having no luck. – jim basquiat Nov 17 '17 at 17:02

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.