D
D
Daniil Kvarkovsky2017-08-02 19:46:40
linux
Daniil Kvarkovsky, 2017-08-02 19:46:40

Executing scripts after Linux is fully booted?

The task is to automatically mount the ftp folder at system startup
There is a script that mounts the ftp folder
#!/bin/bash
#HOST=
#FOLDER=
curlftpfs $HOST/$FOLDER /mnt/ftp -o allow_other,codepage=windows-1251[,iocharset= utf8] 2>>/adminfolder/log/error.log
exit 0
Script added to crontab
@reboot root /adminfolder/scripts/ftp_conn.sh #Execute after restart
Question: How can I force the script to be executed only after the network is fully loaded? Or maybe there is another option to mount ftp after a system restart. (There is an option with adding a line to /etc/fstab)
With these parameters in crontab, network-related errors in the log:
Error connecting to ftp: Could not resolve host: @[email protected]; Unknown error
Error connecting to ftp: Failed to connect to @[email protected]: Network is unreachable
CentOS 7.3 system
PS
There is an option to add a line to /etc/fstab
curlftpfs# ftp://ftp.host.ru/folder/ /mnt/ftp fuse rw,nosuid,nodev,allow_other,codepage=windows-1251[,iocharset=utf8] 0 0
This option does not suit and it did not work, although the mount -a command is executed normally, but after restarting the system swears at fstab
Thanks in advance for the advice !

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
pfg21, 2017-08-02
@pfg21

Write a systemd script in which to prescribe the necessary requirements in After ??

V
Vladimir Zhurkin, 2017-08-02
@icCE

well, in general, the line for fstab is something like this
curlftpfs# ftp://{user}:{password}@{ server address}/{folder}/ {path to the mount point} fuse rw,allow_other,noauto,user 0 0,
respectively, should be fuse
modprobe fuse
This is the correct way to mount after boot.
Otherwise, write a script and add it to the init part as a service.

D
Daniil Kvarkovsky, 2017-08-18
@siderson

I'll answer my own question!
All the proposed options above are not suitable for a more or less correct implementation of the task.
I had to read about systemd again, after that a unit was created and a script for connecting and mounting ftp was written.
Parameters were specified in the unit
In the [Unit] section we specify that the script should be launched only after the network is started After=network.target
In the [Service] section we specify the oneshot type and add the path to our script ExecStart=/usr/bin/sh /adminfolder/scripts /conn_ftp1.sh), I also specified a parameter so that systemd would not consider that the service is down RemainAfterExit=yes
And in the [Install] section, specify multi-user.target
After that, we add it to auto start and start, check that our unit is working and started without errors systemctl status nameservice.service

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question