run a script a boot


i search an easy way to run a script when the computer boot.

script content is

java -jar myprogram.jar

any idea how to do it?

At boot is a bit vague… :wink:

Is is needed by your user, root, some other user, before the desktop starts, after the desktop starts?

there is no ui…

a ton of service start at boot…
i search to start mine.

You can add your script to /etc/init.d/after.local, or write a systemd unit for it.

Who is running the script, root, your user?

Does it require other services to be running for it to work?

Is it needed by just your user when running a desktop?

any user
just need mysql

there is no ui

I understand it doesn’t need a UI, but it does matter if you want it run as mysql user, or the user or should it be run by the nobody user if no desktop is running. Not trying to confuse you, but surely who ever provides the jar file should tell you what user is running it?

If it’s needed by user mysql, then you should look at a systemd service to start so it runs as the correct user…

So you should look at starting the script as the user you want to run as plus probably need to /dev/null it so it backgrounds?

java -jar myprogram.jar > /dev/null 2>&1

You could then create a systemd service file in /etc/systemd/system to call the above and add the user option to the service file.