I have created and enabled my custom systemd 253.1 service file on Linux. I ran 'systemctl enable samba-container' successfully and the 'systemctl status' command shows that the service is enabled.
I can successfully manually run 'systemctl start samba-container'. The service starts and works as expected. The problem is that I cannot get the service to startup automatically on bootup. There are not errors or other output I can find, the service is just in an inactive state on power up.
Status:
[root@device ~]$ systemctl status samba-container
* samba-container.service - SAMBA Container
Loaded: loaded (/lib/systemd/system/samba-container.service; enabled; preset: disabled)
Active: inactive (dead)
The contents of the file are below (note that ui-container is running and 'active'):
cat /lib/systemd/system/samba-container.service
[Unit]
Description=SAMBA Container
After=ui-container.service
[Service]
TimeoutStartSec=0
TimeoutStopSec=0
TimeoutSec=0
MemoryAccounting=yes
MemoryHigh=128M
MemoryMax=256M
WorkingDirectory=/data
ExecStartPre=/bin/bash -c "sleep 10"
ExecStart=/data/samba.sh
ExecStop=/usr/bin/docker stop samba
[Install]
WantedBy=multi-user.target
The samba.sh script file is shown here:
#!/bin/bash
docker kill samba 1>/dev/null 2>/dev/null
docker rm samba 1>/dev/null 2>/dev/null
iptables -A INPUT -m state --state NEW -p udp --dport 137 -j ACCEPT
iptables -A INPUT -m state --state NEW -p udp --dport 138 -j ACCEPT
iptables -A INPUT -m state --state NEW -p tcp --dport 139 -j ACCEPT
iptables -A INPUT -m state --state NEW -p tcp --dport 445 -j ACCEPT
mkdir -p /data/samba
mkdir -p /data/data
docker run --network host --privileged -v "/data/data:/data" -v "/data/samba:/samba" --name samba crazymax/samba
UPDATE:
[root@machine log]$ cat /lib/systemd/system/samba-container.service
[Unit]
Description=SAMBA Container
After=startup.service network-online.target
[Service]
TimeoutStartSec=0
TimeoutStopSec=0
TimeoutSec=0
MemoryAccounting=yes
MemoryHigh=128M
MemoryMax=256M
WorkingDirectory=/data
ExecStartPre=/bin/bash -c "sleep 10"
ExecStart=/data/samba.sh
ExecStop=/usr/bin/docker stop samba
[Install]
WantedBy=multi-user.target
Online service:
[root@machine log]$ systemctl status network-online.target
* network-online.target - Network is Online
Loaded: loaded (/lib/systemd/system/network-online.target; static)
Active: active since Wed 2024-10-09 13:49:06 UTC; 1min 55s ago
Docs: man:systemd.special(7)
https://systemd.io/NETWORK_ONLINE
Oct 09 13:49:06 machine systemd[1]: Reached target Network is Online.
Startup service:
[root@machine log]$ systemctl status startup
* startup.service - Startup Service
Loaded: loaded (/lib/systemd/system/startup.service; enabled; preset: enabled)
Active: active (running) since Wed 2024-10-09 13:48:36 UTC; 2min 33s ago
Main PID: 516 (startup.sh)
Status: "Startup completed ..."
Tasks: 2 (limit: 4148)
Memory: 7.5M
CGroup: /system.slice/startup.service
|-516 /bin/bash /usr/bin/startup.sh
`-601 sleep infinity
Logs:
[root@machine log]$ cat messages
Oct 9 13:48:35 machine syslog.info syslogd started: BusyBox v1.35.0
Oct 9 13:48:35 machine daemon.info dbus-daemon[459]: [system] Activating via systemd: service name='de.pengutronix.rauc' unit='rauc.service' requested by ':1.5' (uid=0 pid=467 comm="/usr/bin/rauc status mark-good")
Oct 9 13:48:36 machine daemon.info dbus-daemon[459]: [system] Successfully activated service 'de.pengutronix.rauc'
Oct 9 13:48:37 machine daemon.info bluetoothd[579]: Bluetooth daemon 5.65
Oct 9 13:48:37 machine daemon.info bluetoothd[579]: Starting SDP server
Oct 9 13:48:37 machine daemon.err bluetoothd[579]: ../bluez-5.65/src/rfkill.c:rfkill_init() Failed to open RFKILL control device
Oct 9 13:48:37 machine daemon.info bluetoothd[579]: Bluetooth management interface 1.21 initialized
Oct 9 13:48:37 machine daemon.info dbus-daemon[459]: [system] Activating via systemd: service name='org.freedesktop.hostname1' unit='dbus-org.freedesktop.hostname1.service' requested by ':1.7' (uid=0 pid=579 comm="/usr/libexec/bluetooth/bluetoothd")
Oct 9 13:48:37 machine daemon.info dbus-daemon[459]: [system] Activation via systemd failed for unit 'dbus-org.freedesktop.hostname1.service': Unit dbus-org.freedesktop.hostname1.service not found.
Oct 9 13:48:41 machine authpriv.info login[545]: pam_unix(login:session): session opened for user root(uid=0) by LOGIN(uid=0)
Oct 9 13:48:41 machine authpriv.notice (systemd): pam_warn(systemd-user:setcred): function=[pam_sm_setcred] flags=0x8002 service=[systemd-user] terminal=[<unknown>] user=[root] ruser=[<unknown>] rhost=[<unknown>]
Oct 9 13:48:42 machine authpriv.notice login[758]: ROOT LOGIN on '/dev/ttymxc1'