systemd script failing

This forum is for topics specific to the Raspberry Pi and Arch Linux ARM

systemd script failing

Postby okmania » Thu Feb 14, 2013 6:39 am

I created the following script to send me an email on startup, placed it in "/usr/lib/systemd/scripts"

$this->bbcode_second_pass_code('', '
import smtplib
import socket

GMAIL_ADDR = "XXXX"
GMAIL_PW = "XXXX"
TO_ADDR = "XXXX"'

my_ip = socket.gethostbyname(socket.gethostname())

server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
server.login(GMAIL_ADDR, GMAIL_PW)
server.sendmail(GMAIL_ADDR, TO_ADDR, "Raspberry Pie is located at %s" % my_ip)
server.quit()
')

I created the following service and placed in in /usr/lib/systemd/system

$this->bbcode_second_pass_code('', '[Unit]
Description=mail ip on boot

[Service]
Type=oneshot
ExecStart=/usr/lib/systemd/scripts/mail_ip

[Install]
WantedBy=multi-user.target')

The script runs locally but when I boot up I get the following

$this->bbcode_second_pass_code('', '
UNIT LOAD ACTIVE SUB DESCRIPTION
mail_ip.service loaded failed failed mail ip on boot
')

Could it have something to do with the network not being ready yet? Is there any good ways to debug this problem?

Thanks
okmania
 
Posts: 4
Joined: Thu Feb 14, 2013 6:30 am

Re: systemd script failing

Postby moonman » Thu Feb 14, 2013 7:58 am

Add this to Unit section:

$this->bbcode_second_pass_code('', 'After=network.target')
Pogoplug V4 | GoFlex Home | Raspberry Pi 4 4GB | CuBox-i4 Pro | ClearFog | BeagleBone Black | Odroid U2 | Odroid C1 | Odroid XU4
-----------------------------------------------------------------------------------------------------------------------
[armv5] Updated U-Boot | [armv5] NAND Rescue System
moonman
Developer
 
Posts: 3388
Joined: Sat Jan 15, 2011 3:36 am

Re: systemd script failing

Postby okmania » Thu Feb 14, 2013 4:36 pm

Thanks, work's great now.

I there any documentation on the systemd service config file format? I poked around here http://www.freedesktop.org/wiki/Software/systemd and in the man file, and wasn't able to find anything.
okmania
 
Posts: 4
Joined: Thu Feb 14, 2013 6:30 am

Re: systemd script failing

Postby moonman » Fri Feb 15, 2013 8:55 am

I don't know if there's any in-detail documentation, but there are many examples in /usr/lib/systemd/system. Archwiki has some pretty good writeups as well.
Pogoplug V4 | GoFlex Home | Raspberry Pi 4 4GB | CuBox-i4 Pro | ClearFog | BeagleBone Black | Odroid U2 | Odroid C1 | Odroid XU4
-----------------------------------------------------------------------------------------------------------------------
[armv5] Updated U-Boot | [armv5] NAND Rescue System
moonman
Developer
 
Posts: 3388
Joined: Sat Jan 15, 2011 3:36 am


Return to Raspberry Pi

Who is online

Users browsing this forum: No registered users and 8 guests