Many Linux operating systems, like OpenSuse, Fedora are using Systemd daemon instead of Linux init based daemon (known as systemV). Systemd is meant to provide a better framework for expressing services’ dependencies, allow more work to be done in parallel (concurrently) at system startup, and to reduce shell overhead.
I use a script (I made it a service) which gets executed at system boot, this script/service search for certain conditions like network settings and if they are true it reset them with default configuration. Recently I have created a Fedora18 VM and tried to run this service on it but it failed. As Fedora 18 is Systemd based, I now have to configure the script/service to work with it.
Following are the steps which I have followed to create and configure systemd service file.
Note: Location of the script is /etc/init.d/mycustomscript.pl
- Go to systemd directory i.e. /usr/lib/systemd/system/
- Create a new file with name “servicename.service“. In my case I have created file named “mycustomscript.service“
- Add following content in the above file:
After=syslog.target network.target auditd.service[Service]
- Now reload the Systemd Daemon using command “systemctl daemon-reload“. This will notify systemd about new service.
[root@localhost ~]# systemctl daemon-reload
- Test the service you have created by starting it “systemctl start mycustomscript“.
[root@localhost ~]# systemctl start mycustomscript
- Now enable the service “systemctl start mycustomscript”
[root@localhost ~]# systemctl enable mycustomscript
ln -s ‘/usr/lib/systemd/system/mycustomscript.service’ ‘/etc/systemd/system/multi-user.target.wants/mycustomscript.service’
- You can check and verify if the is service properly added in systemd or not using command “systemctl –all | grep mycustomscript“
If you see your service in the list, bingo you have successfully created the service.