Systemd can't execute script which loads kernel module - embedded-linux

When I'm trying to execute script through systemd service - I receive error message and script can't be run.
init_something.service file:
[Unit]
Description=Loading module --module_name module
[Service]
Type=oneshot
ExecStart=/usr/lib/systemd/init_script
[Install]
WantedBy=multi-user.target
init_script file:
#!/bin/bash -
/usr/local/bin/init.sh --module_init
And now if I try to start service by systemctl I receive error message:
# systemctl start init_something.service
Job for init_something.service failed. See 'systemctl status init_something.service' and 'journalctl -xn' for details
# systemctl status init_something.service
init_something.service - Loading module --module_name module
Loaded: loaded (/usr/lib/systemd/init_something.service)
Active: failed (Result: exit-code) since Thu 1970-01-01 08:00:24 CST; 1min 49s ago
Process: 243 ExecStart=/usr/lib/systemd/init_script (code=exited, status=1/FAILURE)
Main PID: 243 (code=exited, status=1/FAILURE)
But if I try to run init_script manualy - it works perfectly:
# /usr/lib/systemd/init_script
[ 447.409277] SYSCLK:S0[...]
[ 477.523434] VIN: (...)
Use default settings
map_size = (...)
u_code version = (...)
etc.
And finally module is loaded successfully.
So the question is - why systemctl can't execute this script, but manually it's no problem?

For running any script file, system needs shell. But systemd do'nt have its own shell. So you need to provide shell for running script.
so use ExecStart=/bin/sh /usr/lib/systemd/init_script in your service unit.
[Unit]
Description=Loading module --module_name module
[Service]
Type=oneshot
ExecStart=/bin/sh /usr/lib/systemd/init_script
[Install]
WantedBy=multi-user.target
And
chmod 777 /usr/lib/systemd/init_script
before running your script.

Related

What is causing the systemd error: "Timer unit lacks value setting" (no other error messages?)

I have the following timer unit:
[Unit]
Description=Timer for Hive management command: process_payments
[Timer]
Unit=hive-manage#process_payments.service
OnCalendar=*:0/20
[Install]
WantedBy=hive.target
When I check the timer status using systemctl status hive-manage#process-payments.timer, I see the following error in the logs:
● hive-manage#process-payments.timer - Timer for Hive management command: process-payments
Loaded: error (Reason: Invalid argument)
Active: inactive (dead)
Mar 02 21:28:39 boldidea systemd[1]: hive-manage#process-payments.timer: Timer unit lacks value setting. Refusing.
Mar 02 21:39:06 boldidea systemd[1]: hive-manage#process-payments.timer: Timer unit lacks value setting. Refusing.
Mar 02 21:39:27 boldidea systemd[1]: hive-manage#process-payments.timer: Timer unit lacks value setting. Refusing.
After some searching, most people get an accompanying message that gives more detail on the error, however I am not getting any context other than "Timer unit lacks value setting".
This error is not very helpful -- I'm unaware of any setting named "value".
It turns out I had an older unit called process-payments, and it was later renamed to process_payments (underscore instead of hyphen). I was referencing the old name in my systemctl status command.

error running a gui application on systemd services

I am trying to run a gui commands in systemd services which i want it to execute on system startup.
these are my files.
oversteer.sh file:
#!/bin/bash
sleep 1s
export DISPLAY=:99.0
export SCREEN_WIDTH=1200
export SCREEN_HEIGHT=960
export SCREEN_DEPTH=24
export GEOMETRY="${SCREEN_WIDTH}x${SCREEN_HEIGHT}x${SCREEN_DEPTH}"
sudo oversteer --autocenter 45 &
sudo oversteer --range 720
oversteer.service file:
[Unit]
Description = oversteer
After=local-fs.target
[Service]
Environment="DISPLAY=:0"
Environment="XAUTHORITY=/home/ubuntu/.Xauthority"
ExecStart=/home/ubuntu/g29_steering_wheel/autostart_scripts/oversteer.sh
Restart=on-failure
Type=simple
StandardOutput=journal+console
[Install]
WantedBy=multi-user.target
I have put this file in /etc/systemd/system and have given executable as well as root permissions. However, it looks like this service fails because of no Display.
error is as follows:
Unable to init server: Could not connect: Connection refused
Unable to init server: Could not connect: Connection refused
Unable to init server: Could not connect: Connection refused
Unable to init server: Could not connect: Connection refused
(oversteer:8052): Gdk-CRITICAL **: 08:00:50.744: gdk_cursor_new_for_display: assertion 'GDK_IS_DISPLAY (display)' failed
(oversteer:8053): Gdk-CRITICAL **: 08:00:50.763: gdk_cursor_new_for_display: assertion 'GDK_IS_DISPLAY (display)' failed
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/matplotlib/backends/backend_gtk3.py", line 45, in <module>
cursors.MOVE : Gdk.Cursor.new(Gdk.CursorType.FLEUR),
TypeError: constructor returned NULL
I am running on raspi 4 with ubuntu 20.04. The oversteer is a package for controlling the parameters of my joystick.

Installing navidrome throws "Unit navidrome.service is not loaded properly: Exec format error."

While installing navidrome I am getting this error:
hardik:/etc/systemd/system$ sudo systemctl start navidrome.service
Failed to start navidrome.service: Unit navidrome.service is not loaded properly: Exec format error.
See system logs and 'systemctl status navidrome.service' for details.
The content of navidrome.service is given below:-
navidrome.service
[Unit]
Description=Navidrome Music Server and Streamer compatible with Subsonic/Airsonic
After=remote-fs.target network.target
AssertPathExists=/var/lib/navidrome
[Install]
WantedBy=multi-user.target
[Service]
User=<user>
Group=<group>
Type=simple
ExecStart=/opt/navidrome/navidrome --configfile "/var/lib/navidrome/navidrome.toml"
WorkingDirectory=/var/lib/navidrome
TimeoutStopSec=20
KillMode=process
Restart=on-failure
# See https://www.freedesktop.org/software/systemd/man/systemd.exec.html
DevicePolicy=closed
NoNewPrivileges=yes
PrivateTmp=yes
PrivateUsers=yes
ProtectControlGroups=yes
ProtectKernelModules=yes
ProtectKernelTunables=yes
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
RestrictNamespaces=yes
RestrictRealtime=yes
SystemCallFilter=~#clock #debug #module #mount #obsolete #reboot #setuid #swap
ReadWritePaths=/var/lib/navidrome
# You can uncomment the following line if you're not using the jukebox This
# will prevent navidrome from accessing any real (physical) devices
#PrivateDevices=yes
# You can change the following line to `strict` instead of `full` if you don't
# want navidrome to be able to write anything on your filesystem outside of
# /var/lib/navidrome.
ProtectSystem=full
# You can uncomment the following line if you don't have any media in /home/*.
# This will prevent navidrome from ever reading/writing anything there.
#ProtectHome=true
# You can customize some Navidrome config options by setting environment variables here. Ex:
#Environment=ND_BASEURL="/navidrome"
Why am I getting the error and how do I fix it?
I had the same error when I was trying to start the service on my raspberry pi 3 using navidrome_0.47.5_Linux_arm64.tar.gz. When I replaced it with files from navidrome_0.47.5_Linux_armv7.tar.gz, everything went fine. It's likely that you might be trying to run the executable with a wrong architecture.
Also I believe that User and Group should contain the actual user and group that you chose here:
sudo install -d -o <user> -g <group> /opt/navidrome
sudo install -d -o <user> -g <group> /var/lib/navidrome

Why I got errors running redis in laravel app?

I need to run laravel 5 app on my local Kubuntu 18 and I need to run redis server for this app
I installed and in file /etc/redis/redis.conf I uncommented line :
requirepass foobared
in .env I modified redis config :
REDIS_HOST=http://127.0.0.1:8000 # I run app with command : php artisan serve
REDIS_PASSWORD=foobared
REDIS_PORT=6379 # default port
I restarted redis and check status:
$ sudo service redis status
[sudo] password for serge:
● redis-server.service - Advanced key-value store
Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2021-02-26 13:52:09 EET; 6min ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Process: 1545 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=0/SUCCESS)
Process: 1548 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf (code=exited, status=0/SUCCESS)
Main PID: 1574 (redis-server)
Tasks: 4 (limit: 4915)
CGroup: /system.slice/redis-server.service
└─1574 /usr/bin/redis-server 127.0.0.1:6379
Feb 26 13:52:08 AtHome systemd[1]: Starting Advanced key-value store...
Feb 26 13:52:09 AtHome systemd[1]: redis-server.service: Can't open PID file /var/run/redis/redis-server.pid (yet?) after start: No such file or directory
Feb 26 13:52:09 AtHome systemd[1]: Started Advanced key-value store.
I see that file Can't open PID file not found above
But I have this file:
root#AtHome:/run/redis# ls -la
total 4
drwxr-sr-x 2 redis redis 60 Feb 26 14:32 .
drwxr-xr-x 38 root root 1160 Feb 26 14:32 ..
-rw-rw---- 1 redis redis 6 Feb 26 14:32 redis-server.pid
root#AtHome:/run/redis# cat redis-server.pid
22676
aand I got error on next command :
$ laravel-echo-server start
Error: The config file could not be found.
Is this errors as PID file was not found above?
How can it be fixed?
In composer.json :
"laravel/framework": "5.5.*",
"predis/predis": "^1.1",
MODIFIED # :
In /etc/redis/redis.conf I found
pidfile /var/run/redis/redis-server.pid
When I installed the ubuntu I installed /var on separate partition, so I have in /etc/fstab :
UUID=e531d8c5-530c-4533-a949-9fd5a62e0821 / ext4 errors=remount-ro 0 1
# /boot was on /dev/sdb1 during installation
UUID=23cc34a1-2be9-43b1-9c79-8e53af7bc799 /boot ext4 defaults 0 2
# /var was on /dev/sdb5 during installation
UUID=57c14b70-da85-4c5b-be6f-45174147d987 /var ext4 defaults 0 2
that is why /var/run/redis/redis-server.pid looks like /run/redis/redis-server.pid in my console command.
I do not know can that be key of this problem? How can it be salved ?
MODIFIED # 2 :
Yes, redis started and it shows in status command :
Active: active (running)
I see error message
Feb 26 13:52:09 AtHome systemd[1]: redis-server.service: Can't open PID file /var/run/redis/redis-server.pid
I do not know how critical is it ?
I need to run in the root of my app laravel-echo-server for redis working
but I got error :
$ laravel-echo-server start
Error: The config file could not be found.
I suppose that 2) depends on 1), but not sure, I am new in redis and very common
knowledge about laravel-echo-server...
MODIFIED # 3 :
Searching how test redis I found how made tests, but looks like not all works properly :
app_root$ redis-cli
127.0.0.1:6379> set greetings "Hello World!"
(error) NOAUTH Authentication required.
127.0.0.1:6379> get greetings
(error) NOAUTH Authentication required.
127.0.0.1:6379> exit
app_root$ sudo systemctl restart redis
[sudo] password for serge:
app_root$ redis-cli
127.0.0.1:6379> get greetings
(error) NOAUTH Authentication required.
127.0.0.1:6379>
But I am still not sure if it is reason that I got error running laravel-echo-server
Thanks!

systemd: How to use ExecStopPre in service files

Before my daemon is stopped I need to do call another program.
My first try was to use ExecStopPre similar to ExecStartPre but according to https://bugs.freedesktop.org/show_bug.cgi?id=73177 this is not supported and I should use "multiple ExecStop".
Anyone got an example for this? How should i kill the daemon from ExecStop?
You put multiple lines with ExecStop (from a node.js service): e.g.
[Service]
ExecStartPre=/usr/local/bin/npm run build
ExecStartPre=-/bin/rm local.sock
ExecStart=/usr/local/bin/npm --parseable start
ExecStop=/usr/local/bin/npm --parseable stop
ExecStop=-/bin/rm local.sock
RestartSec=300
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=nodejs
User=nobody
Group=nobody
Environment=NODE_ENV=dev
Environment=PORT=3000
WorkingDirectory=/var/www/nodejs/quaff
UMask=007

Resources