How do I get this systemd script to work on ArchLinux? - linux

I have a firewire device hooked into a machine running arch linux.
I got FFADO working, and after I execute ffado-dbus-server I can start using the firewire device with Jack and Pulseaudio (that convolution is entirely unrelated to my issue here)
I basically have to run 3 different steps each time I boot to get my sound working. I'm trying to get all of this magic to happen automatically at boot.
I read about /etc/rc.local but it seems that no such file exists on my arch linux install. I read about the boot process on arch linux and it seems that arch doesn't use rc.local and instead uses systemd
I went through the arch wiki page on systemd and tried to create a simple ffado-dbus.service unit file in /usr/lib/systemd/system
I started trying to use a unit type of dbus, then tried oneshot, and finally simple
No matter what I do the results are pretty much consistent. The service fails.
I also tried putting the service in usr/lib/systemd/user and tried running this as systemctl --user start but that also produced the same failure.
The simplest example of the unit file I have is this:
[Unit]
Description=FFADO DBus startup
[Service]
Type=simple
ExecStart=/usr/sbin/ffado-dbus-server
That produces the following status:
[pigdog#livingroom system]$ sudo systemctl status ffado-dbus -l
● ffado-dbus.service - FFADO DBus Service
Loaded: loaded (/usr/lib/systemd/system/ffado-dbus.service; static; vendor preset: disabled)
Active: failed (Result: core-dump) since Sun 2015-03-01 04:31:59 MST; 5s ago
Process: 3934 ExecStart=/usr/bin/ffado-dbus-server (code=dumped, signal=ABRT)
Main PID: 3934 (code=dumped, signal=ABRT)
Mar 01 04:31:59 livingroom ffado-dbus-server[3934]: FFADO Control DBUS service
Mar 01 04:31:59 livingroom ffado-dbus-server[3934]: Part of the FFADO project -- www.ffado.org
Mar 01 04:31:59 livingroom ffado-dbus-server[3934]: Version: 2.2.1-Unversioned directory
Mar 01 04:31:59 livingroom ffado-dbus-server[3934]: (C) 2008, Pieter Palmers
Mar 01 04:31:59 livingroom ffado-dbus-server[3934]: This program comes with ABSOLUTELY NO WARRANTY.
Mar 01 04:31:59 livingroom ffado-dbus-server[3934]: -----------------------------------------------
Mar 01 04:31:59 livingroom systemd[1]: ffado-dbus.service: main process exited, code=dumped, status=6/ABRT
Mar 01 04:31:59 livingroom systemd[1]: Unit ffado-dbus.service entered failed state.
Mar 01 04:31:59 livingroom systemd[1]: ffado-dbus.service failed.
Mar 01 04:32:00 livingroom systemd-coredump[3944]: Process 3934 (ffado-dbus-serv) of user 0 dumped core.
There is some mysterious code 6/ABRTthat happens in the main process of ffado-dbus-server
I assume this is because the "environment" that systemd is running in doesn't contain processes or something that ffado needs to run. What I don't understand is how I determine what is missing, and then how do I provide this to the systemd environemnt.
Alternatively, I'd love to just make the systemd environment match the "pigdog" user environment from which I just executed the systemctl call. I thought that's what I'd be doing by moving the ffado-dbus.service file into /usr/lib/systemd/user and then calling systemctl like systemctl --user but this produces the same error.
I also tried adding the User=pigdog directive to the [Service] section of the unit file with no success.
I can run /usr/bin/ffado-dbus-server from bash while logged in as pigdog without issue. I get the following output when the script succeeds:
[pigdog#livingroom system]$ /usr/bin/ffado-dbus-server
-----------------------------------------------
FFADO Control DBUS service
Part of the FFADO project -- www.ffado.org
Version: 2.2.1-Unversioned directory
(C) 2008, Pieter Palmers
This program comes with ABSOLUTELY NO WARRANTY.
-----------------------------------------------
1425209640984446: (ffado-dbus-server.cpp)[ 270] main: Discovering devices...
00973362057: Debug (devicemanager.cpp)[ 354] discover: Starting discovery...
00973405357: Debug (devicemanager.cpp)[ 616] discover: driver found for device 0
00973405880: Debug (devicemanager.cpp)[ 653] discover: discovery of node 0 on port 0 done...
00973405944: Debug (devicemanager.cpp)[ 661] discover: Discovery finished...
00973405980: Debug (devicemanager.cpp)[1258] showDeviceInfo: ===== Device Manager =====
00973406020: Debug (Element.cpp)[ 121] show: Element DeviceManager
00973406047: Debug (devicemanager.cpp)[1266] showDeviceInfo: --- IEEE1394 Service 0 ---
00973406085: Debug (devicemanager.cpp)[1276] showDeviceInfo: --- Device 0 ---
00973406113: Debug (devicemanager.cpp)[1279] showDeviceInfo: Clock sync sources:
00973406165: Debug (devicemanager.cpp)[1288] showDeviceInfo: Type: Internal , Id: 0, Valid: 1, Active: 1, Locked 1, Slipping: 0, Description: Internal sync
00973406199: Debug (devicemanager.cpp)[1288] showDeviceInfo: Type: ADAT , Id: 1, Valid: 1, Active: 1, Locked 1, Slipping: 0, Description: ADAT optical
00973406237: Debug (devicemanager.cpp)[1288] showDeviceInfo: Type: SPDIF , Id: 2, Valid: 1, Active: 1, Locked 1, Slipping: 0, Description: SPDIF/Toslink
00973406266: Debug (devicemanager.cpp)[1288] showDeviceInfo: Type: Erratic type , Id: 3, Valid: 0, Active: 0, Locked 0, Slipping: 0, Description: SMPTE
00973406303: Debug (devicemanager.cpp)[1288] showDeviceInfo: Type: WordClock , Id: 4, Valid: 1, Active: 1, Locked 1, Slipping: 0, Description: Wordclock
00973409421: (ffado-dbus-server.cpp)[ 329] main: DBUS service running
00973409433: (ffado-dbus-server.cpp)[ 330] main: press ctrl-c to stop it & exit
00973409436: Debug (ffado-dbus-server.cpp)[ 333] main: dispatching...

When you run a startup script from a shell prompt, and it works, but the startup script fails when launched from systemd -- as is apparently in your case -- ninety nine times out of a hundred the problem is the environment.
I would investigate it as a first order of business -- whether the ffado package sets up some default shell environment variables that are needed by its startup script.
If so, then this becomes a simple matter of setting up the same environment variables before executing the startup script, in the systemd unit file.

Related

Systemd service wont execute at boot

I've created my own Service with systemd. It is supposed to run a python script once at boot time. It sends an Email with the IP-Address and the Teamviewer id, this is why i have an delay in it, otherwise i get an error that the domain of the Mailserver cant be resolved. The Script should run in the background because of the 30 seconds delay.
The script is located in /usr/bin/glatv.py and is ecexuteable, the script run without an problem. The construct is runnning on an Raspberry Pi4 with Raspian Buster 2020-02-13
The Service is in /etc/systemd/system/ located, is executeable and enabled:
[Unit]
Description=My Own Service
[Service]
Type=oneshot
ExecStart=/usr/bin/glatv.py &
[Install]
WantedBy=reboot.target
But
systemctl start myservice
is working without a Problem
● glatvd.service - My Own Service
Loaded: loaded (/etc/systemd/system/glatvd.service; enabled; vendor preset: enabled)
Active: inactive (dead)
Apr 02 12:52:31 raspberrypi systemd[1]: Starting My Own Service...
Apr 02 12:53:02 raspberrypi systemd[1]: glatvd.service: Succeeded.
Apr 02 12:53:02 raspberrypi systemd[1]: Started My Own service.
after a reboot there is no call or log
Instead of having an arbitrary 30-second delay, add this to your service file:
After=network-online.target
Wants=network-online.target
You should try run this command to make your service enable to run after restart
systemctl enable myservice
and for log, I believe you must put this parameters into your service's config file
StandardOutput=/path/to/info/log/info_log.log
StandardError=/path/to/error/log/error_log.log
Anything I got this reference: How to redirect output of systemd service to a file

Issues using Systemd to start a python script (code=exited, status=2/INVALIDARGUMENT)

I'm currently trying to have a program startup when the Raspberry Pi 3 I'm using boots. The program controls a drone and will need a network connection before starting. When I try to use Systemd to start this program, I get this error message;
droneStartup.service - The Drone Startup service.
Loaded: loaded (/etc/systemd/system/droneStartup.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2019-04-15 14:06:24 EDT; 1s ago
Process: 1895 ExecStart=/bin/bash /home/pi/Systemd_test.py (code=exited, status=2)
Main PID: 1895 (code=exited, status=2)
Apr 15 14:06:24 pi systemd[1]: Started The Drone Startup service..
Apr 15 14:06:24 pi bash[1895]: from: can't read /var/mail/time
Apr 15 14:06:24 pi bash[1895]: /home/pi/Systemd_test.py: line 4: syntax error near unexpected token `'Looping...''
Apr 15 14:06:24 pi bash[1895]: /home/pi/Systemd_test.py: line 4: ` print('Looping...')'
Apr 15 14:06:24 pi systemd[1]: droneStartup.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Apr 15 14:06:24 pi systemd[1]: droneStartup.service: Unit entered failed state.
Apr 15 14:06:24 pi systemd[1]: droneStartup.service: Failed with result 'exit-code'.
This is the placeholder program I'm using to test the startup;
from time import sleep
while True :
print('Looping...')
sleep(1)
And this is the .service file I'm using;
[Unit]
Description=The Drone Startup service.
Wants=network-online.target
After=network-online.target
[Service]
ExecStart=/bin/bash /home/pi/Systemd_test.py
[Install]
WantedBy=multi-user.target
I don't know why it's coming up with a syntax error, and would greatly appreciate any help with this issue.
You are attempting to run a py file with bash exec.
Needs to read:
ExecStart=/usr/bin/python /home/pi/Systemd_test.py
Assuming your Python library lives at /usr/bin/python

Puppet Server not starting up in Centos7

I have recently installed puppet5 in Centos7 (Running in VirtualBox). After installation I tried starting it which thrown the below message.
Is there anything should I do with configuration?
[root#puppet ~]# systemctl status puppetserver -l
● puppetserver.service - puppetserver Service
Loaded: loaded (/usr/lib/systemd/system/puppetserver.service; enabled; vendor preset: disabled)
Active: activating (start) since Thu 2018-01-25 13:59:44 IST; 32s ago
Control: 10284 (bash)
CGroup: /system.slice/puppetserver.service
├─10284 bash /opt/puppetlabs/server/apps/puppetserver/cli/apps/start
├─10291 java -Xms2g -Xmx2g -XX:MaxPermSize=256m -Djava.security.egd=/dev/urandom -XX:OnOutOfMemoryError=kill -9 %p -cp /opt/puppetlabs/server/apps/puppetserver/puppet-server-release.jar:/opt/puppetlabs/server/apps/puppetserver/jruby-1_7.jar:/opt/puppetlabs/server/data/puppetserver/jars/* clojure.main -m puppetlabs.trapperkeeper.main --config /etc/puppetlabs/puppetserver/conf.d --bootstrap-config /etc/puppetlabs/puppetserver/services.d/,/opt/puppetlabs/server/apps/puppetserver/config/services.d/ --restart-file /opt/puppetlabs/server/data/puppetserver/restartcounter
└─10366 sleep 1
Jan 25 13:59:44 puppet systemd[1]: Starting puppetserver Service...
Journal Logs:
Jan 25 14:01:29 puppet puppetserver[10419]: Background process 10426 exited before start had completed
Jan 25 14:01:29 puppet systemd[1]: puppetserver.service: control process exited, code=exited status=1
Jan 25 14:01:29 puppet systemd[1]: Failed to start puppetserver Service.
-- Subject: Unit puppetserver.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit puppetserver.service has failed.
--
-- The result is failed.
It looks like the VM has insufficient memory to run the server.
Edit the file /etc/default/puppetserver and lower the values of
JAVA_ARGS=" -Xms2g -Xmx2g ...
to:
JAVA_ARGS="-Xms1g -Xmx1g ...
The VM must have at least 1GB RAM configured with the edited settings.

Configuring twitch lambdabot as a service on NixOS

What I tried:
in /etc/nixos/configuration.nix:
services.lambdabot.enable = true;
services.lambdabot.script ="
rc /var/lib/lambdabot/.lambdabot/creds.rc
irc-connect twitch irc.chat.twitch.tv 6667 IsoMorpheus Lambda_Robots:_100%_Loyal
admin + twitch:IsoMorpheus
join twitch:#freeman42x";
in /var/lib/lambdabot/.lambdabot/creds.rc:
irc-password oauth:6q9hoi2notaellmugrr3alh9yjx8ua
Then:
nixos-rebuild switch
chown lambdabot /var/lib/lambdabot/.lambdabot/creds.rc
systemctl restart lambdabot
Checking HTOP it can be seen that the service is running but the bot does not connect to the IRC channel.
Settings from the manual:
services.lambdabot.enable
Enable the Lambdabot IRC bot
Type: boolean
Default: false
Declared by:
<nixpkgs/nixos/modules/services/networking/lambdabot.nix>
services.lambdabot.script
Lambdabot script
Type: string
Default: ""
Declared by:
<nixpkgs/nixos/modules/services/networking/lambdabot.nix>
Launching lambdabot manually it connects fine and it replies to commands:
https://github.com/lambdabot/lambdabot/blob/1d1ed3e7980081c9f356f8d2fd8ca2771c0ed4f4/lambdabot-core/README.md#connecting
Any suggestions of how to launch it as a service?
[root#nixos:/home/neo]# systemctl status lambdabot
● lambdabot.service - Lambdabot daemon
Loaded: loaded (/nix/store/ifwgvglg3vzndk5wssb66vdz9j9rdflf-unit-lambdabot.service/lambdabot.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2018-01-27 23:53:33 EET; 1min 32s ago
Main PID: 4749 (lambdabot-start)
Tasks: 8 (limit: 4915)
CGroup: /system.slice/lambdabot.service
├─4749 /nix/store/jgw8hxx7wzkyhb2dr9hwsd9h2caaasdc-bash-4.4-p12/bin/bash -e /nix/store/0c6ya3n4bz6id840f4gprv3ly24808rn-unit-script/bin/lambdabot-start
├─4753 /nix/store/jgw8hxx7wzkyhb2dr9hwsd9h2caaasdc-bash-4.4-p12/bin/bash -e /nix/store/0c6ya3n4bz6id840f4gprv3ly24808rn-unit-script/bin/lambdabot-start
├─4754 /nix/store/h0z0pf4ix0ilx5j1x6sk1rfkpjcyjhvc-lambdabot-5.1.0.1/bin/lambdabot
└─4755 cat /run/lambdabot/offline
Jan 27 23:53:33 nixos systemd[1]: Started Lambdabot daemon.
Jan 27 23:53:37 nixos lambdabot-start[4749]: [WARNING] Plugin.seen: WARNING: failed to read Seen module state: Data.Binary.Get.runGet at position 0: not enough bytes
Jan 27 23:53:37 nixos lambdabot-start[4749]: CallStack (from HasCallStack):
Jan 27 23:53:37 nixos lambdabot-start[4749]: error, called at libraries/binary/src/Data/Binary/Get.hs:342:5 in binary-0.8.3.0:Data.Binary.Get
Jan 27 23:53:37 nixos lambdabot-start[4749]: Plugin `offlineRC' failed with: /var/lib/lambdabot/.lambdabot/State: createDirectory: permission denied (Permission denied)
The issue is that I set permission on the creds.rc file instead of on the entire folder, fix:
chown -R lambdabot:users /var/lib/lambdabot/.lambdabot

Systemd script fail

I want to run a script at system startup in a Debian 9 box. My script works when run standalone, but fails under systemd.
My script just copies a backup file from a remote server to the local machine:
#!/bin/sh
set -e
/usr/bin/sshpass -p "PASSWORD" /usr/bin/scp -p USER#10.0.0.2:ORIGINPATH/backupserver.zip DESTINATIONPATH/backupserver/
Just for privacy I replaced password, user, and paths above.
I wrote the following systemd service unit:
[Unit]
Description=backup script
[Service]
Type=oneshot
ExecStart=PATH/backup.sh
[Install]
WantedBy=default.target
Then I set permissions for the script:
chmod 744 PATH/backup.sh
And installed the service:
chmod 664 /etc/systemd/system/backup.service
systemctl daemon-reload
systemctl enable backup.service
When I reboot the script fails:
● backup.service - backup script
Loaded: loaded (/etc/systemd/system/backup.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sat 2017-05-13 13:39:54 -03; 47min ago
Main PID: 591 (code=exited, status=1/FAILURE)
Result of journalctl -xe:
mai 16 23:34:27 rodrigo-acer systemd[1]: backup.service: Main process exited, code=exited, status=6/NOTCONFIGURED
mai 16 23:34:27 rodrigo-acer systemd[1]: Failed to start backup script.
mai 16 23:34:27 rodrigo-acer systemd[1]: backup.service: Unit entered failed state.
mai 16 23:34:27 rodrigo-acer systemd[1]: backup.service: Failed with result 'exit-code'.
What could be wrong?
Solved guys. There was 2 problems:
1 - I had to change the service unit file to make the service run only after network was up. The unit section was changed to:
[Unit]
Description = World server backup
Wants = network-online.target
After = network.target network-online.target
2 - The root user did not have the remote host added to the known host list, unlike the ordinary user I used to test the script.
Failed with result 'exit-code' you could try this on your last line:
# REQUIRED FOR SYSTEMD: 0 means clean no error
exit 0
You may also need to add:
Type=forking
to the systemd entry similar to: https://serverfault.com/questions/751030/systemd-ignores-return-code-while-starting-service
If your service or script does not fork add a & at the end to run it in the background, and exit with 0 fast. Otherwise it will be like a startup that times out and takes forever / seems like frozen service.

Resources