You are not logged in.

#1 2021-10-02 18:42:52

Morta
Member
Registered: 2019-07-07
Posts: 655

Script returns error after execute from systemd

Hi,
i want to execute rc.local (a bash script) after Network  and NetworkManager is on

systemctl edit --full rc-local.service

[Unit]
Description=Boot up Network
Wants=network-online.target
After=NetworkManager.service

[Service]
Type=oneshot
User=root
Group=root
ExecStart=/etc/rc.local
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

cat /etc/rc.local

#!/bin/bash
#Delete old NetworkManager Connections
nmcli connection delete local
nmcli connection delete local-nas

#NetworkManager forward IPv4&IPv6 to Laptop
nmcli connection add type ethernet ifname enp6s0 ipv4.method shared con-name local
nmcli connection modify local ipv6.method shared
nmcli c mod enp2s0 ipv6.token ::deca:fbad:c0:ffee

#NetworkManager forward IPv4 to NAS
nmcli connection add type ethernet ifname enp5s0 ipv4.method shared con-name local-nas
nmcli connection modify local-nas ipv6.method shared

#Forward Internet to Laptop with Iptables
sysctl net.ipv4.ip_forward=1
iptables -t nat -A POSTROUTING -o enp2s0 -j MASQUERADE
iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i enp6s0 -o enp2s0 -j ACCEPT
iptables -A FORWARD -i enp5so -o enp2s0 -j ACCEPT

#Loopback for fastcg/php-fpm
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT

#Iptables rules for speedtesting.it
iptables -A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -m state --state NEW -p tcp --dport 443 -j ACCEPT

#Iptables rules for rsync
iptables -A INPUT -m state --state NEW -p tcp --dport 873 -j ACCEPT
iptables -A INPUT -m state --state NEW -p udp --dport 873 -j ACCEPT


ip6tables -A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT
ip6tables -A INPUT -m state --state NEW -p tcp --dport 443 -j ACCEPT

#Iptabels rules for mopidy
iptables -A INPUT -m state --state NEW -p tcp --dport 6680 -j ACCEPT
ip6tables -A INPUT -m state --state NEW -p tcp --dport 6680 -j ACCEPT

#Docker ipv6
ip6tables -t nat -A POSTROUTING -s fd00::/80 ! -o docker0 -j MASQUERADE


#Rights for Certbot Let's Encrypt Floder
chgrp -R ssl-cert /etc/letsencrypt
chmod -R 2755 /etc/letsencrypt

sudo journalctl -xeu rc-local.service

░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░ 
░░ An ExecStart= process belonging to unit rc-local.service has exited.
░░ 
░░ The process' exit code is 'exited' and its exit status is 1.
Oct 02 19:30:24 5erver systemd[1]: rc-local.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░ 
░░ The unit rc-local.service has entered the 'failed' state with result 'exit-code'.
Oct 02 19:30:24 5erver systemd[1]: Failed to start Boot up Network.
░░ Subject: A start job for unit rc-local.service has failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░ 
░░ A start job for unit rc-local.service has finished with a failure.
░░ 
░░ The job identifier is 2368 and the job result is failed.
Oct 02 19:31:40 5erver systemd[1]: Starting Boot up Network...
░░ Subject: A start job for unit rc-local.service has begun execution
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░ 
░░ A start job for unit rc-local.service has begun execution.
░░ 
░░ The job identifier is 2613.
Oct 02 19:31:40 5erver rc.local[18640]: Verbindung »local« (a8f8e340-78eb-4a38-b97f-3260adfaf17e) erfolgreich gelöscht.
Oct 02 19:31:40 5erver rc.local[18645]: Verbindung »local-nas« (574e15a5-cb1e-4814-a2da-d4aa45e8dd89) erfolgreich gelöscht.
Oct 02 19:31:40 5erver rc.local[18659]: Verbindung »local« (36b17a0a-6188-41ca-8c77-c32de52ccaec) erfolgreich hinzugefügt.
Oct 02 19:31:40 5erver rc.local[18685]: Verbindung »local-nas« (09de7f0f-c809-4ff4-b3b7-fc95f9bbc296) erfolgreich hinzugefügt.
Oct 02 19:31:40 5erver rc.local[18693]: net.ipv4.ip_forward = 1
Oct 02 19:31:40 5erver systemd[1]: rc-local.service: Main process exited, code=exited, status=1/FAILURE
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░ 
░░ An ExecStart= process belonging to unit rc-local.service has exited.
░░ 
░░ The process' exit code is 'exited' and its exit status is 1.
Oct 02 19:31:40 5erver systemd[1]: rc-local.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░ 
░░ The unit rc-local.service has entered the 'failed' state with result 'exit-code'.
Oct 02 19:31:40 5erver systemd[1]: Failed to start Boot up Network.
░░ Subject: A start job for unit rc-local.service has failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░ 
░░ A start job for unit rc-local.service has finished with a failure.
░░ 
░░ The job identifier is 2613 and the job result is failed.

What is wrong?

Offline

#2 2021-10-02 20:37:33

seth
Member
Registered: 2012-09-03
Posts: 49,979

Re: Script returns error after execute from systemd

The tailing commands fail (ie. chmod fails. possibly chown - possibly iptables but that gets increasinly unlikely)

#!/bin/bash
echo foo
true
echo bar
false
#!/bin/bash
echo foo
false
echo bar
true

Edit: check "echo $?" after running those scripts.

You could "exit 0" but I guess rather want to invesitigate why chmod/chown fail (missing file?)

Last edited by seth (2021-10-02 20:38:03)

Offline

#3 2021-10-03 11:18:56

Morta
Member
Registered: 2019-07-07
Posts: 655

Re: Script returns error after execute from systemd

seth wrote:

The tailing commands fail (ie. chmod fails. possibly chown - possibly iptables but that gets increasinly unlikely)

#!/bin/bash
echo foo
true
echo bar
false
#!/bin/bash
echo foo
false
echo bar
true

Edit: check "echo $?" after running those scripts.

You could "exit 0" but I guess rather want to invesitigate why chmod/chown fail (missing file?)

 
I can execute rc.local with sudo bash /etc/rc.local and get no error. I will add echo $ to be shure that shows me exit 0.

The other two scripts i run as service and look that shows me exit 0 on boot up?

Offline

#4 2021-10-03 13:28:41

seth
Member
Registered: 2012-09-03
Posts: 49,979

Re: Script returns error after execute from systemd

The script could fail early on because the file is not *yet* there or for other reasons.
You could append "|| echo $LINENO" to every command in the script to get an idea what fails, but since it has to be at the tail, it's gonna be around the /etc/letsencrypt altering calls.

Offline

#5 2021-10-03 13:51:06

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,425

Re: Script returns error after execute from systemd

How up to date are you? There was a bug in coreutils 9.0-1 that lead to chmod having a wrong exit code under certain recursive adjustments (... iirc if the recursed dir contained symlinks) should be fixed in 9.0-2

Online

#6 2021-10-04 16:04:33

Morta
Member
Registered: 2019-07-07
Posts: 655

Re: Script returns error after execute from systemd

V1del wrote:

How up to date are you? There was a bug in coreutils 9.0-1 that lead to chmod having a wrong exit code under certain recursive adjustments (... iirc if the recursed dir contained symlinks) should be fixed in 9.0-2

I have now updated coreutils and will watch after a reboot if the script is working again.

Thanks for the input!

Offline

Board footer

Powered by FluxBB