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: https://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
Neat. Thanks a lot!
By: Anonymous on June 12, 2013
at 5:26 am
Sometimes, you get customers who change the structure of a website, and
the search engines still know about the old structure, so people click on links that take them to missing pages.
This is easy to fix.
If you want to redirect missing pages to the index.html page of a website, put this line into the .
htaccess file inside of the root of the domain. Sometimes, this is /web or /httpdocs.
By: Linux Administrator on July 6, 2013
at 10:32 am
Simple, and easy. Thank you so much!
By: Anonymous on October 6, 2013
at 10:26 pm
[…] https://kezhong.wordpress.com/2011/11/19/creating-my-own-systemd-service-files-on-fedora-16x86_64/ […]
By: How To: Configure Synergy Client systemd Service Auto-Start in Linux (Fedora 20) - Stephan's Home & Tech Info on January 31, 2014
at 2:33 pm
[…] https://kezhong.wordpress.com/2011/11/19/creating-my-own-systemd-service-files-on-fedora-16x86_64/ […]
By: How To: Configure Synergy Server as a systemd Service in Linux (Fedora 20) - Stephan's Home & Tech Info on August 2, 2014
at 9:08 am
I like what youu guys are usuially up too. This type of clever work and exposure!
Keep up the wonderful works guys I’ve incorporated you guys to my own blogroll.
By: Asterisk Setup Ubuntu on August 18, 2014
at 8:42 am
good example, Thanks
By: Anonymous on April 20, 2015
at 7:46 am
Thank you for this article, it was very helpful! Systemd is a pain the ass, but it does make things easier once you get the hang of it’s commands.
By: Anonymous on July 9, 2015
at 5:26 pm
[…] following this tutorial (https://kezhong.wordpress.com/2011/11/19/creating-my-own-systemd-service-files-on-fedora-16x86_64/) to add a new systemd .service, but it does’nt work, i did step by step correct with some […]
By: Adding a systemd .service (Debian) | Asking on September 10, 2015
at 5:23 pm