1 year ago

#374014

test-img

LoF10

having issues getting systemd process to execute successfully?

I am currently trying to set up a bash script that records the ipv6 address of a host machine (raspberry pi running buster) and writes it to an env file the script creates. The script runs fine if I execute manually, but it doesn't seem to execute successfully on boot when enabled; I don't see the env file it is supposed to create in the appropriate directory.

I wonder if this is a permissions issue in regard to creating the .env file? Hoping someone might be able to shed light on how to trouble shoot this? I have set the following permissions on files as well as tried feed -c type to the exec start option.

OS and hardware:

OS: buster lite
host: raspberry pi 4

Permissions and prep:

# copy file to the bin folder and add permissions
cp /home/pi/my_project/ip_addr/linux_get_ip.sh /usr/local/bin/linux_get_ip.sh
sudo chmod 744 /usr/local/bin/linux_get_ip.sh
sudo chmod 644 /etc/systemd/system/get_ip.service

Bash script: linux_get_ip.sh

#!/bin/bash

# test existence of a directory
cd ./my_project/ip_addr/

# create an env file
touch .env

# assign the ip address to that env file
MACHINE_HOST_IP="$(hostname -I | cut -d " " -f 2)"
echo "${MACHINE_HOST_IP}"
echo "$(ls)"
destdir=.env
echo "MACHINE_HOST_IP=$MACHINE_HOST_IP" > "$destdir"

Service: get_ip.service

[Unit]
 Description=Get IP address of local machine
 After=multi-user.target

 [Service]
 Type=idle
 ExecStart=/bin/bash -c /usr/local/bin/linux_get_ip.sh

 [Install]
 WantedBy=multi-user.target

systemctl status get_ip.service

ā— get_ip.service - Get IP address of local machine
     Loaded: loaded (/etc/systemd/system/get_ip.service; enabled; vendor preset: enabled)
     Active: inactive (dead) since Mon 2022-04-04 12:26:31 EDT; 8min ago
    Process: 1235 ExecStart=/bin/bash -c /usr/local/bin/linux_get_ip.sh (code=exited, status=0/SUCCESS)
   Main PID: 1235 (code=exited, status=0/SUCCESS)
        CPU: 51ms

Apr 04 12:26:31 raspberrypi bash[1235]: proc
Apr 04 12:26:31 raspberrypi bash[1235]: root
Apr 04 12:26:31 raspberrypi bash[1235]: run
Apr 04 12:26:31 raspberrypi bash[1235]: sbin
Apr 04 12:26:31 raspberrypi bash[1235]: srv
Apr 04 12:26:31 raspberrypi bash[1235]: sys
Apr 04 12:26:31 raspberrypi bash[1235]: tmp
Apr 04 12:26:31 raspberrypi bash[1235]: usr
Apr 04 12:26:31 raspberrypi bash[1235]: var
Apr 04 12:26:31 raspberrypi systemd[1]: get_ip.service: Succeeded.

bash

raspberry-pi

systemd

systemctl

0 Answers

Your Answer

Accepted video resources