Systemd runs script multiple times.

Hi there, I just got my BBB and have created a python script that waits until the BBB can see the internet and then sends an email to sms to tell me what the IP on eth0 is.

The script works fine when run from the command line, but when I created a systemd service to launch it at boot it seems to run the script 10-15 times. Which, as you can guess is pretty annoying. It runs out on its own eventually and issuing a stop does not seem to help.

Here is a chunk of the log file from journalctl, if you want to see the code let me know.

Jan 01 01:27:10 beaglebone sendip[676]: Successfully sent email
Jan 01 01:27:11 beaglebone sendip[678]: Successfully sent email
Jan 01 01:27:12 beaglebone sendip[680]: Successfully sent email
Jan 01 01:27:12 beaglebone sendip[682]: Successfully sent email
– Reboot –
Jan 01 01:54:01 beaglebone sendip[132]: Successfully sent email
Jan 01 01:54:08 beaglebone sendip[362]: Successfully sent email
Jan 01 01:54:10 beaglebone sendip[429]: Successfully sent email
Jan 01 01:54:12 beaglebone sendip[439]: Successfully sent email
Jan 01 01:54:14 beaglebone sendip[446]: Successfully sent email
Jan 01 01:54:17 beaglebone sendip[455]: Successfully sent email
Jan 01 01:54:22 beaglebone sendip[492]: Successfully sent email
Jan 01 01:54:25 beaglebone sendip[495]: Successfully sent email
Jan 01 01:54:26 beaglebone sendip[519]: Successfully sent email

Any thoughts? I know the time is not set yet, that is the next thing I am going to work on.

Thanks.

What does your systemd service file look like?

This is what I have. I actually built a workaround for now, my script creates a file in the ram drive, and if the file already exists it stops. I would like to know why it is doing it though

[Unit]
Description=Send IP address to phone when internet is up

[Service]
Type=forking
WorkingDirectory=/var/lib/cloud9/
ExecStart=/usr/bin/python iptest.py
Restart=always
StandardOutput=syslog
SyslogIdentifier=sendip

[Install]
WantedBy=multi-user.target

Thanks!

It could be…

http://www.freedesktop.org/software/systemd/man/systemd.service.html

“If set to forking, it is expected that the process configured with ExecStart= will call fork() as part of its start-up.”

If you’re just using a python script, you want “simple” for the type, where the service is considered running as long as the process is alive (assuming your iptest.py script stays alive).

If this script exits, or fails, it’ll be restarted over and over again with your “Restart=always”.

I just noticed the restart=always.

I have a pretty good feeling that is the issue.
Oops.