Nusrat Nuriyev
asked on
Adding custom startup script on fedora.
Performed actions:
Script used
/etc/init.d/mysript
Content of script
Commands performed:
Testing workability:
ps ax | grep "myexecutable"
Does not give myexecutable as an output, so we conclude that application does not start.
Wishes:
The application must start on startup.
Thank you.
Script used
/etc/init.d/mysript
Content of script
#!/bin/bash
# chkconfig: 345 90 10
# description: Description comes here....
### BEGIN INIT INFO
# Required-Start: $sendmail $mysqld $httpd
# Required-Stop: $sendmail $mysqld $httpd
# Default-Start: 345
# Default-Stop: 0126
### END INIT INFO
# Source function library
. /etc/rc.d/init.d/functions
mystart() {
su -c '/myexecutable start' ejudge
}
mystop() {
su -c '/myexecutable stop' ejudge
}
case "$1" in
start)
mystart
;;
stop)
mystop
;;
restart)
mystop
mystart
;;
*)
echo "Usage: $0 start|stop|restart"
exit 1
esac
exit 0
Commands performed:
chmod a+x myscript
chkconfig --add myscript
chkconfig --level 2345 myscript on
Testing workability:
ps ax | grep "myexecutable"
Does not give myexecutable as an output, so we conclude that application does not start.
Wishes:
The application must start on startup.
Thank you.
Hi, what version is your Fedora? Are you using an older version with SysVinit or a newer one with Systemd, seeing you're using chkconfig it should be a system using SysVinit ...
ASKER
Fedora 20.
Briefly, describe the differences between SysVinit and Systemd, and how to determine which one I belong
Briefly, describe the differences between SysVinit and Systemd, and how to determine which one I belong
There is no immediate default way to check if you have either SysVinit or Systemd or Upstart for that matter, there is a way you can check, like this for example:
But since it is Fedora 20 it is using Systemd by default normally ...
To know some differences between Systemd and SysVinit, check this list
If you want to run a script at startup you can create a Systemd file in /usr/lib/systemd/system/<y our_servic e_name>.se rvice.
It should look something like this:
Change the things between the brackets to comply with your setup.
Now tell Systemd to enable this service:
Reboot the system and see if the script runs like it should.
Check the messages log for info if it fails ( /var/log/messages).
ps -eaf|grep [s]ystemd
But since it is Fedora 20 it is using Systemd by default normally ...
To know some differences between Systemd and SysVinit, check this list
If you want to run a script at startup you can create a Systemd file in /usr/lib/systemd/system/<y
It should look something like this:
[Unit]
Description=<description>
[Service]
WorkingDirectory=<directory_of_script>
Type=forking
ExecStart=/bin/bash <the_absolute_path_to_script>
KillMode=process
[Install]
WantedBy=multi-user.target
Change the things between the brackets to comply with your setup.
Now tell Systemd to enable this service:
systemctl enable <your_service_name>.service
Reboot the system and see if the script runs like it should.
Check the messages log for info if it fails ( /var/log/messages).
ASKER
Thank you for systemd versus sysvinit information
Could we use command line arguments here?
ExecStart=/bin/bash <the_absolute_path_to_scri pt>
Likewise
ExecStart=/bin/bash <the_absolute_path_to_scri pt> <argument1> <argument2>
?
Could we use command line arguments here?
ExecStart=/bin/bash <the_absolute_path_to_scri
Likewise
ExecStart=/bin/bash <the_absolute_path_to_scri
?
ASKER
Another question is how to execute at shutdown which is binded to this service unit?
Actually, as you may see, I use single application which is started by
myexecutable start
and
terminate by
myexecutable stop
In sysvinit we have ability to do this, what about systemd?
Actually, as you may see, I use single application which is started by
myexecutable start
and
terminate by
myexecutable stop
In sysvinit we have ability to do this, what about systemd?
If I understand your first question here, then yes you can, check out the Fedora info here
I'm not sure I understand your second question completely, but in systemd you can start stop a service like this:
systemctl start service.name
and
systemctl stop service.name
I'm not sure I understand your second question completely, but in systemd you can start stop a service like this:
systemctl start service.name
and
systemctl stop service.name
ASKER
Then, systemd is not flexible enough, because I can't pass arguments to the executable, right?
Then, let's assume that we will solve the problem with good old sysinit?
Thank you.
Then, let's assume that we will solve the problem with good old sysinit?
Thank you.
What are your arguments?
If you look at this example you can give certain arguments:
If you look at this example you can give certain arguments:
[Unit]
Description=Avahi mDNS/DNS-SD Stack
Requires=avahi-daemon.socket
[Service]
Type=dbus
BusName=org.freedesktop.Avahi
ExecStart=/usr/sbin/avahi-daemon -s
ExecReload=/usr/sbin/avahi-daemon -r
NotifyAccess=main
[Install]
WantedBy=multi-user.target
Also=avahi-daemon.socket
Alias=dbus-org.freedesktop.Avahi.service
ASKER
What is ExecReload?
It's used when your application/service supports reloading ... So as the name of it suggest.
You can leave this option blank if your service doesn't support it.
You can leave this option blank if your service doesn't support it.
ASKER
ok, what happened with the service state when system shutdown?
is it killed?
is it killed?
As far as I understand, the service file is also touched by the shutdown command, so you can normally just leave it as is, it will shutdown the service.
You can add a timeout under [service] if you want, for example:
You can add a timeout under [service] if you want, for example:
TimeoutSec=300
System V init scripts run inder both upstart (ubuntu, RHEL6) and systemd (Rhel7 etc)
No need to reinvent the wheel for every system.
No need to reinvent the wheel for every system.
ASKER
It does not work.
When I manually start it /etc/init.d/myscript start
it works.
But it does not work on system startup.
It says something like "can't connect to mysql via socket."
When I manually start it /etc/init.d/myscript start
it works.
But it does not work on system startup.
It says something like "can't connect to mysql via socket."
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Maybe mariadb?
What does mean "name is being provided in EL7"? name of the package?
What does mean "name is being provided in EL7"? name of the package?
Thats the question.
No - sysV init scripts provide facilities like $local_fs or $network
So systemD does provide something similar, but you need to look into systemd descriptor what it is.
No - sysV init scripts provide facilities like $local_fs or $network
So systemD does provide something similar, but you need to look into systemd descriptor what it is.