Posted by: kezhong | November 19, 2011

Creating my own systemd service files on Fedora 16(x86_64)

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

About these ads

Responses

  1. Thank you. This helps me; a simple example in a simple format.

  2. 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/”?

  3. [...] 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 [...]

  4. I want to setup offlineimap to sync my maildir periodicaly and this is exactly what I was looking for :).

    Great post, thanks!

  5. [...] Ref: https://kezhong.wordpress.com/2011/11/19/creating-my-own-systemd-service-files-on-fedora-16x86_64/ [...]

  6. Great example!

  7. Neat. Thanks a lot!

  8. 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.

  9. Simple, and easy. Thank you so much!

  10. […] https://kezhong.wordpress.com/2011/11/19/creating-my-own-systemd-service-files-on-fedora-16x86_64/ […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

Follow

Get every new post delivered to your Inbox.

Join 28 other followers

%d bloggers like this: