Ubuntu : Automatically start GUI application at startup - linux

I would like to start a GUI application when the session starts
It is a CM4 with a 5 inch touch screen, the purpose is to launch an application when Ubuntu starts.
Via a terminal, when I start it (./main) it works without problem
I tried via startup applications but it doesn't work, I don't know why
I tried via systemd but it doesn't seem to work for graphical applications
[Unit]
After=network.service
[Service]
ExecStart=/home/ubuntu/path/main
[Install]
WantedBy=multi-user.target
I tried via /etc/rc5.d but that doesn't work either
What am I doing wrong?

Related

Nitrogen through systemd services doesn't work

I am writing a tool (zxcV32/OpenRWC) that fetches wallpapers from Reddit and sets them to the monitor(s) using nitrogen.
To make it easy to install and run automatically, I have created a deb package and a systemd service.
When the service is started using
sudo systemctl start openrwc#$USER.service
nitrogen errors out with exit status 1. (No other error message). And yes, the exec installed by the deb package works fine when manually run from the terminal.
I have compared that the command run by the tool is precisely the same when run through the systemd service or terminal run.
Sample command
nitrogen --set-scaled /home/zxcv32/.config/OpenRWC/fz41kmzk1wj91.jpg --head=0
Service
[Unit]
Description=Reddit Wallpaper Changer for GNU/Linux
Requires=display-manager.service
After=display-manager.service
StartLimitIntervalSec=0
[Service]
Type=simple
ExecStart=/usr/bin/openrwc
Restart=always
RestartSec=5
User=%i
[Install]
WantedBy=graphical.target
What may be wrong with the service? I want the service to be the user's choice, if they want to run it or not.
BTW I found this question that claims that nitrogen works through a service. (maybe there is a difference between running nitrogen directly through system service and through a go funciton)
System: Debian 11 5.10.0-17-amd64
Found the issue.
Systemd does not have access to certain environment variables.
DISPLAY environment variable needs to be set in the openrwc#.service.
[Service]
Environment="DISPLAY=:0"

self contained asp.net core app runs fine when started via command line,- but when started as service under linux it crashes immediately

I have a self-contained ASP.net core app which works fine when started via command line on Linux Ubuntu.
If I try to start the same app as a service, it starts but crashes immediately.
The service file looks like this:
[UNIT]
Description=.....
[Service]
workingDirectory=/etc/www/api
ExecStart=/etc/www/api/API.Web
User=root
[Install]
WantedBy=multi-user.target
Hint: I just used root as user for demo purposes. When going live this will be a dedicated user with limited rights. --> It also does not work with a specific user with limited rights.
The crash error message when doing service status is:
What could cause such a strange behavior and how to avoid it.

What is the best way to run a Node.js script as service in Ubuntu?

I have a Node.js script that keeps my MongoDB database and the CRM database synced in real-time.
I want to run this script as a background task on my Ubuntu server. I found this solution, but it doesn't work for me. Is there another approach to reach this?
If you just want to start your application, you could use Forever or PM2 for running and auto-restarting on crash. However, this is not a background task.
For a background task that starts on server reboot, the post you linked is the right way to go. If it didn't work, maybe this article will help you. This is from official Express site: Process managers for Express apps
Basically, you create
[Unit]
Description="My Express App"
[Service]
ExecStart=/usr/bin/node server.js
WorkingDirectory=/project/absolute/path
Restart=always
RestartSec=10
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=MyApp
Environment=NODE_ENV=production PORT=8080
[Install]
WantedBy=multi-user.target
Into a /etc/systemd/system/my-app.service file and then use systemctl to start it:
systemctl enable my-app.service
systemctl start my-app.service
Now this assumes your Linux distribution works with systemctl. If your Linux distribution works with upstart or something else, then you need to google up the instruction for that process manager.

program running a boot on BeagleBoneblack

I am having a problem with a small application I developed on the BBB running Debian Image 2017-03-19.
I connected a barcode scanner to the usb port and a 2x16 LCD display to the GPIO controlled by BBBioLib.
I developed an application in C to read a barcode label apply to a race tyre, which find a match on an SQLite table and show the racer name on the display.
Application work great but since the all assembly must work stand alone I need to run the program automatically at boot.
I follow all the instruction on creating a bash program and service but I am getting a strange behaviour.
The display after the welcome message hang up and never change but the application work correctly because all the printf to the consolle get logged correctly and once I exit the application I can check them on the log of the service.
If I restart the service manually everything work fine.
This is the bash script
#!/bin/bash
/root/read_barcode
This is the service code
[Unit]
Description=Barcode reader launch
After=syslog.target network.target
[Service]
Type=simple
ExecStart=/usr/bin/barcode.sh
[Install]
WantedBy=multi-user.target
Does anyone can help on solving this problem.
Thanks
Carlo
Run a .service file with sudo systemctl enable YourService.service at this location.
/etc/systemd/system/
Use the enable option for systemd .service files to make your source work on boot or a reboot.

Running K Kestrel in the background

How does one run the Kestrel webserver in a persistent way on Linux / OSX? I am able to run the webserver as expected with:
k kestrel
However, I have not found a way to background it for persistence, i.e.
k kestrel &
The process starts then immediately stops.
Just try to use
nohup k kestrel &
Tested with CentOS 7 (64 bit)
Works as expected :)
You can also create init.d script which will use start-stop-daemon together with nohup to control your application (not only start in the background, but also stop, autostart at system startup, etc)
Here is script template
And here are instructions how to install and configure it
For centos7 you can create systemd wrapper:
File /etc/systemd/system/kestrel-test.service:
[Unit]
Description=Web .Net Application running on Centos
[Service]
WorkingDirectory=/www/site.tld/htdocs
ExecStart=/usr/bin/dotnet /www/site.tld/htdocs/bin/Debug/netcoreapp2.0/asp.net.dll
Restart=always
RestartSec=10
SyslogIdentifier=dotnet-example
User=aspnetcoreuser
Environment=ASPNETCORE_ENVIRONMENT=Production
[Install]
WantedBy=multi-user.target
Then, you can manage it via sudo service kestrel-test start (stop, status).
Also it works for other systemd OS like Ubuntu16.

Resources