systemd is a replacement for the System V init daemon for Linux. It is intended to provide a better framework for expressing services’ dependencies, allow more work to be done in parallel at system startup, and to reduce shell overhead. It has been used starting with Fedora 15.
On my environment, the system is Fedora 16(X86_64). I want to send my radius log to another web server per 5 second so as to monitor it conveniently.
Create the script file
# vi /usr/local/bin/radinfo
#!/bin/bash
while true
do
ext=$(date +%y%m%d-%H%M%S)
tail -200 /var/log/radius/radius.log > /dev/shm/radinfo
scp /dev/shm/radinfo kezhong@192.168.1.20:/var/www/html/radinfo/r$ext
ssh kezhong@192.168.1.20 “find /var/www/html/radinfo/ -cmin +60 -exec rm {} \;”
sleep 5
done
Give it execute permission
# chmod u+x /usr/local/bin/radinfo
Create the service file
# vi /lib/systemd/system/radinfo.service
[Unit]
Description=Sending radius log to management server
After=syslog.target network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/radinfo
[Install]
WantedBy=multi-user.target
Make symbolic link
# cd /etc/systemd/system/
# ln -s /lib/systemd/system/radinfo.service radinfo.service
Make systemd take notice of it
# systemctl daemon-reload
Activate a service immediately
# systemctl start radinfo.service
Enable a service to be started on bootup
# systemctl enable radinfo.service
Reference
all of systemd’s man pages
Thank you. This helps me; a simple example in a simple format.
By: Thomas on November 22, 2011
at 12:11 pm
Thank you, your post was very useful to me!
Just a question: Defining “WantedBy=multi-user.target”, the symbolic link should not be in “/etc/systemd/system/multi-user.target/”?
By: Oscar Costa on January 29, 2012
at 8:18 pm
[...] scheduler. I am still learning about this, but according to the wikipedia entry and also to Kezhong’s Weblog, this daemon is meant to efficiently express services dependencies, by allowing more services to be [...]
By: » Start a C program when BeagleBone boots Wunderkammer on April 10, 2012
at 10:04 pm
I want to setup offlineimap to sync my maildir periodicaly and this is exactly what I was looking for :).
Great post, thanks!
By: astro on August 15, 2012
at 5:37 pm
[...] Ref: http://kezhong.wordpress.com/2011/11/19/creating-my-own-systemd-service-files-on-fedora-16x86_64/ [...]
By: phoenixdigital.com » Blog Archive » Creating services for Linux with systemd on October 14, 2012
at 8:29 pm
Great example!
By: Jean Carlo Machado on November 4, 2012
at 9:39 pm