0

Running Fedora 33/34 on multiple machines. I successfully activated rc-local.service which works fine. I have couple of other scripts that I need to run in /etc/init.d/ and I created similar service files as rc-local.service, but I can't enable it, whereas rc-local.service can be enabled/disabled/stared/stopped without any troubles.
I know, that I have an option (which I currently use) to call those scripts from rc.local file, but would rather called them separately as service. So my service file looks like this:
#cat net-scr1.service

[Unit]
Description=Network check service
ConditionFileIsExecutable=/etc/init.d/net-scr1
After=network.target 

[Service]
Type=forking
ExecStart=/etc/init.d/net-scr1 start
TimeoutSec=3
ExecStop=/etc/init.d/net-scr1 stop
RemainAfterExit=yes
GuessMainPID=no
StandardOutput=tty

[Install]
 WantedBy=multi-user.target

systemctl enable net-scr1

Synchronizing state of net-scr1.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable net-scr1
service net-scr1 does not support chkconfig

I moved the script out of init.d thinking maybe systemd assumes it's an old sysv script, but no change. What should I have in my script to work properly?
My script looks like:

#!/bin/bash
EMFR=admin@server1.com
eml=admin@mydomain.com
dv0=p1p1
ipdv0=`ifconfig $dv0 | grep "inet " | awk '{print $2}'`
if [ "$1" = "stop" ]; then
  cat $msg | mail $EMFR -s "$srv-shut_down-ip-$ipdv0" $eml
fi
if [ "$1" = "start" ]; then
  cat $msg | mail $EMFR -s "$srv-booted_up-ip-$ipdv0" $eml  

fi

Should I include Functions from the old sysv system or something else? Thanks

DenisZ
  • 38
  • 7

2 Answers2

0

See this

  1. cd /etc/systemd/system
  2. Create a file named your-service.service and include the following:
[Unit]
Description=<description about this service>

[Service]
User=<user e.g. root>
WorkingDirectory=<directory_of_script e.g. /root>
ExecStart=<script which needs to be executed>
Restart=always

[Install]
WantedBy=multi-user.target
Haim Cohen
  • 111
  • 2
  • This is what I have done as you can see from my unit file. but it doesn't want to enable service, as I posted above response. – DenisZ May 30 '21 at 13:21
0

I've found a solution. I have included following 3 lines on top of my script:
head /etc/init.d/net-scr1

# net-scr1          Start/Stop the net script1
# chkconfig: 345 90 10
# description: net-scr1 sends alert on reboot

now systemctl enable net-scr1 works fine

DenisZ
  • 38
  • 7