xorbit / LiFePO4wered-Pi

Access library, command line tool and daemon for the LiFePO4wered/Pi module
GNU General Public License v2.0
132 stars 31 forks source link

Newly (re-)installed daemon fails to start #63

Closed garethhowell closed 1 year ago

garethhowell commented 1 year ago

I needed to rebuild the Pi 3B my LifePO4wered-Pi+ is connected to.

I followed the same installation instructions as before, but lifepo4wered-daemon.service fails to start.

If I can get in quickly, then I can start it manually using sudo systemctl start lifepo4wered-daemon (Not sure if it's relevant, but although I've changed PI_BOOT_TO to 600s, it still gives up after a couple of minutes)

In case it's a timing problem, I've tried changing the service file to introduce an ExecPreStart of 30s but it makes no difference.

The unit file looks like:

[Unit]
Description=emonHub data multiplexer
# The config file lives in /etc/emonhub/emonhub.conf
# The log file lives in /var/log/emonhub/emonhub.log
#Requires=var-log.mount
#After=var-log.mount network.target
After=network.target

[Service]
Type=exec
ExecStart=/usr/local/bin/emonhub/emonhub.py --config-file=/etc/emonhub/emonhub.conf --logfile=/var/log/emonhub/emonhub.log
User=pi
Environment='USER=pi'
Environment='LOG_PATH=/var/log/emonhub'
PermissionsStartOnly=true
ExecStartPre=/bin/mkdir -p ${LOG_PATH}
ExecStartPre=/bin/chown ${USER} ${LOG_PATH}

Restart=always
RestartSec=5

SyslogIdentifier=emonhub

[Install]
WantedBy=multi-user.target

Note: I had to edit out the Requires for var-log.mount because detain bullseye doesn't have that mount systemctl show emonhub shows

Type=exec
Restart=always
NotifyAccess=none
RestartUSec=5s
TimeoutStartUSec=1min 30s
TimeoutStopUSec=1min 30s
TimeoutAbortUSec=1min 30s
TimeoutStartFailureMode=terminate
TimeoutStopFailureMode=terminate
RuntimeMaxUSec=infinity
WatchdogUSec=0
WatchdogTimestampMonotonic=0
RootDirectoryStartOnly=no
RemainAfterExit=no
GuessMainPID=yes
MainPID=0
ControlPID=0
FileDescriptorStoreMax=0
NFileDescriptorStore=0
StatusErrno=0
Result=exit-code
ReloadResult=success
CleanResult=success
UID=[not set]
GID=[not set]
NRestarts=97
OOMPolicy=stop
ExecMainStartTimestampMonotonic=0
ExecMainExitTimestampMonotonic=0
ExecMainPID=0
ExecMainCode=0
ExecMainStatus=0
ExecStartPre={ path=/bin/mkdir ; argv[]=/bin/mkdir -p ${LOG_PATH} ; ignore_errors=no ; start_time=[Sun 2023-08-27 12:24:13 BST] ; stop_time=[Sun 2023-08-27 12:24:13 BST] ; pid=2220 ; code=exited ; status=217 }
ExecStartPre={ path=/bin/chown ; argv[]=/bin/chown ${USER} ${LOG_PATH} ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }
ExecStartPreEx={ path=/bin/mkdir ; argv[]=/bin/mkdir -p ${LOG_PATH} ; flags= ; start_time=[Sun 2023-08-27 12:24:13 BST] ; stop_time=[Sun 2023-08-27 12:24:13 BST] ; pid=2220 ; code=exited ; status=217 }
ExecStartPreEx={ path=/bin/chown ; argv[]=/bin/chown ${USER} ${LOG_PATH} ; flags= ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }
ExecStart={ path=/usr/local/bin/emonhub/emonhub.py ; argv[]=/usr/local/bin/emonhub/emonhub.py --config-file=/etc/emonhub/emonhub.conf --logfile=/var/log/emonhub/emonhub.log ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }
ExecStartEx={ path=/usr/local/bin/emonhub/emonhub.py ; argv[]=/usr/local/bin/emonhub/emonhub.py --config-file=/etc/emonhub/emonhub.conf --logfile=/var/log/emonhub/emonhub.log ; flags= ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }
Slice=system.slice
MemoryCurrent=[not set]
CPUUsageNSec=0
EffectiveCPUs=
EffectiveMemoryNodes=
TasksCurrent=[not set]
IPIngressBytes=[no data]
IPIngressPackets=[no data]
IPEgressBytes=[no data]
IPEgressPackets=[no data]
IOReadBytes=18446744073709551615
IOReadOperations=18446744073709551615
IOWriteBytes=18446744073709551615
IOWriteOperations=18446744073709551615
Delegate=no
CPUAccounting=yes
CPUWeight=[not set]
StartupCPUWeight=[not set]
CPUShares=[not set]
StartupCPUShares=[not set]
CPUQuotaPerSecUSec=infinity
CPUQuotaPeriodUSec=infinity
AllowedCPUs=
AllowedMemoryNodes=
IOAccounting=no
IOWeight=[not set]
StartupIOWeight=[not set]
BlockIOAccounting=no
BlockIOWeight=[not set]
StartupBlockIOWeight=[not set]
MemoryAccounting=yes
DefaultMemoryLow=0
DefaultMemoryMin=0
MemoryMin=0
MemoryLow=0
MemoryHigh=infinity
MemoryMax=infinity
MemorySwapMax=infinity
MemoryLimit=infinity
DevicePolicy=auto
TasksAccounting=yes
TasksMax=1595
IPAccounting=no
ManagedOOMSwap=auto
ManagedOOMMemoryPressure=auto
ManagedOOMMemoryPressureLimitPercent=0%
Environment=USER=pi LOG_PATH=/var/log/emonhub
UMask=0022
LimitCPU=infinity
LimitCPUSoft=infinity
LimitFSIZE=infinity
LimitFSIZESoft=infinity
LimitDATA=infinity
LimitDATASoft=infinity
LimitSTACK=infinity
LimitSTACKSoft=8388608
LimitCORE=infinity
LimitCORESoft=0
LimitRSS=infinity
LimitRSSSoft=infinity
LimitNOFILE=524288
LimitNOFILESoft=1024
LimitAS=infinity
LimitASSoft=infinity
LimitNPROC=5319
LimitNPROCSoft=5319
LimitMEMLOCK=8388608
LimitMEMLOCKSoft=8388608
LimitLOCKS=infinity
LimitLOCKSSoft=infinity
LimitSIGPENDING=5319
LimitSIGPENDINGSoft=5319
LimitMSGQUEUE=819200
LimitMSGQUEUESoft=819200
LimitNICE=0
LimitNICESoft=0
LimitRTPRIO=0
LimitRTPRIOSoft=0
LimitRTTIME=infinity
LimitRTTIMESoft=infinity
RootHashSignature=
OOMScoreAdjust=0
CoredumpFilter=0x33
Nice=0
IOSchedulingClass=0
IOSchedulingPriority=0
CPUSchedulingPolicy=0
CPUSchedulingPriority=0
CPUAffinity=
CPUAffinityFromNUMA=no
NUMAPolicy=n/a
NUMAMask=
TimerSlackNSec=50000
CPUSchedulingResetOnFork=no
NonBlocking=no
StandardInput=null
StandardInputData=
StandardOutput=journal
StandardError=inherit
TTYReset=no
TTYVHangup=no
TTYVTDisallocate=no
SyslogPriority=30
SyslogIdentifier=emonhub
SyslogLevelPrefix=yes
SyslogLevel=6
SyslogFacility=3
LogLevelMax=-1
LogRateLimitIntervalUSec=0
LogRateLimitBurst=0
SecureBits=0
CapabilityBoundingSet=cap_chown cap_dac_override cap_dac_read_search cap_fowner cap_fsetid cap_kill cap_setgid cap_setuid cap_setpcap cap_linux_immutable cap_net_bind_service cap_net_broadcast cap_net_admin cap_net_raw cap_ipc_lock cap_ipc_owner cap_sys_module cap_sys_rawio cap_sys_chroot cap_sys_ptrace cap_sys_pacct cap_sys_admin cap_sys_boot cap_sys_nice cap_sys_resource cap_sys_time cap_sys_tty_config cap_mknod cap_lease cap_audit_write cap_audit_control cap_setfcap cap_mac_override cap_mac_admin cap_syslog cap_wake_alarm cap_block_suspend cap_audit_read cap_perfmon cap_bpf cap_checkpoint_restore
AmbientCapabilities=
User=root\nEnvironment="USER=root"
DynamicUser=no
RemoveIPC=no
MountFlags=
PrivateTmp=no
PrivateDevices=no
ProtectClock=no
ProtectKernelTunables=no
ProtectKernelModules=no
ProtectKernelLogs=no
ProtectControlGroups=no
PrivateNetwork=no
PrivateUsers=no
PrivateMounts=no
ProtectHome=no
ProtectSystem=no
SameProcessGroup=no
UtmpMode=init
IgnoreSIGPIPE=yes
NoNewPrivileges=no
SystemCallErrorNumber=2147483646
LockPersonality=no
RuntimeDirectoryPreserve=no
RuntimeDirectoryMode=0755
StateDirectoryMode=0755
CacheDirectoryMode=0755
LogsDirectoryMode=0755
ConfigurationDirectoryMode=0755
TimeoutCleanUSec=infinity
MemoryDenyWriteExecute=no
RestrictRealtime=no
RestrictSUIDSGID=no
RestrictNamespaces=no
MountAPIVFS=no
KeyringMode=private
ProtectProc=default
ProcSubset=all
ProtectHostname=no
KillMode=control-group
KillSignal=15
RestartKillSignal=15
FinalKillSignal=9
SendSIGKILL=yes
SendSIGHUP=no
WatchdogSignal=6
Id=emonhub.service
Names=emonhub.service
Requires=system.slice sysinit.target
WantedBy=multi-user.target
Conflicts=shutdown.target
Before=multi-user.target shutdown.target
After=basic.target network.target sysinit.target system.slice systemd-journald.socket
Description=emonHub data multiplexer
LoadState=loaded
ActiveState=activating
FreezerState=running
SubState=auto-restart
FragmentPath=/etc/systemd/system/emonhub.service
DropInPaths=/usr/lib/systemd/system/emonhub.service.d/emonhub.conf
UnitFileState=enabled
UnitFilePreset=enabled
StateChangeTimestamp=Sun 2023-08-27 12:24:13 BST
StateChangeTimestampMonotonic=1324758725
InactiveExitTimestamp=Sun 2023-08-27 12:24:13 BST
InactiveExitTimestampMonotonic=1324758725
ActiveEnterTimestampMonotonic=0
ActiveExitTimestampMonotonic=0
InactiveEnterTimestamp=Sun 2023-08-27 12:24:13 BST
InactiveEnterTimestampMonotonic=1324754732
CanStart=yes
CanStop=yes
CanReload=no
CanIsolate=no
CanFreeze=yes
StopWhenUnneeded=no
RefuseManualStart=no
RefuseManualStop=no
AllowIsolate=no
DefaultDependencies=yes
OnFailureJobMode=replace
IgnoreOnIsolate=no
NeedDaemonReload=no
JobTimeoutUSec=infinity
JobRunningTimeoutUSec=infinity
JobTimeoutAction=none
ConditionResult=yes
AssertResult=yes
ConditionTimestamp=Sun 2023-08-27 12:24:13 BST
ConditionTimestampMonotonic=1324660354
AssertTimestamp=Sun 2023-08-27 12:24:13 BST
AssertTimestampMonotonic=1324660370
Transient=no
Perpetual=no
StartLimitIntervalUSec=10s
StartLimitBurst=5
StartLimitAction=none
FailureAction=none
SuccessAction=none
InvocationID=dbaec0c683af4addaa22d008a84cc681
CollectMode=inactive

and the journal shows

Aug 27 12:26:08 docker4 systemd[1]: Starting emonHub data multiplexer...
░░ Subject: A start job for unit emonhub.service has begun execution
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ A start job for unit emonhub.service has begun execution.
░░ 
░░ The job identifier is 9748.
Aug 27 12:26:08 docker4 systemd[1]: emonhub.service: Control process exited, code=exited, status=217/USER
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ An ExecStartPre= process belonging to unit emonhub.service has exited.
░░ 
░░ The process' exit code is 'exited' and its exit status is 217.
Aug 27 12:26:08 docker4 systemd[1]: emonhub.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ The unit emonhub.service has entered the 'failed' state with result 'exit-code'.
Aug 27 12:26:08 docker4 systemd[1]: Failed to start emonHub data multiplexer.
░░ Subject: A start job for unit emonhub.service has failed
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ A start job for unit emonhub.service has finished with a failure.
░░ 
░░ The job identifier is 9748 and the job result is failed.

It fails with status=217/USER but I fail to see why. the user pi exists and I can run the code manually.

Any ideas?

xorbit commented 1 year ago

I am confused, what is "emonhub"?

To be honest, I know very little of systemd and its service integration, this part was contributed by a user.

garethhowell commented 1 year ago

I'm not surprised :-) I included the wrong unit file. However, if you didn't provide the unit file in the first place, I'll do some more digging.

In the meantime, I'll disable the unit and start the daemon from rc.local instead.