Reputation: 141
I have a oneshot service which I want to start at boot time on rhel 7.4.
I understand that "chkconfig --add"
is one way to achieve this. But it requires the startup script to be present in
/etc/init.d directory
For non-oneshot services, I understand that the "Restart=" option could be used in the systemd service file.
If I try to set Restart=always
for a oneshot service, it doesn't work. Oneshot service needs "Restart=no"
.
Is there any way I can start a oneshot service upon boot without having the script in
/etc/init.d directory
Upvotes: 2
Views: 3788
Reputation: 1468
First of all, since we have not mentioned your Systemd service, here an example:
Example filename:
/etc/systemd/system/my-startup-script.service
Example content:
[Unit]
Description=My startup script
#After=network.target
[Service]
Type=oneshot
ExecStart=/root/my-startup-script.sh
RemainAfterExit=true
[Install]
WantedBy=multi-user.target
After that, just enable it:
systemctl daemon-reload
systemctl enable my-startup-script
In this way you have enabled your service. So, after every reboot, your oneshot service (or whatever normal service) will be executed.
That's all my friend!
Upvotes: 2
Reputation: 141
"systemctl enable" takes care of starting any service, be it oneshot or other.
Upvotes: 2