In Ubuntu 16.04 I need to run 4 commands automatically at system startup in the interval of a few seconds each, so that the previous command can start. Did in / /etc/rc.local but does not work. And if you do everything manually everything works.

Here are the commands:

sudo systemctl start mongodb

cd / opt / parse-server-example

sudo screen npm start

sudo screen parse-dashboard - config config.json - allowInsecureHTTP = 1

Help me please. Thank.

Ps. GUI no

  • Add sleep 1 after each command. - aleks.andr
  • did not help (((( - Zhan
  • And if you specify the full path to all files and programs? - don Rumata
  • one
    The key phrase "to let the previous team have time to start" is the basic systemd functionality. You just need to read the documentation. And no slips. - KoVadim
  • one
    KoVadim is right, this is a typical "hammer error . " It is necessary not to wait for the amount of time, but wait just for the start of the service. - D-side

3 answers 3

Use this command in the same /etc/rc.local or shove a script into .sh and put it in crowns for the @reboot event

 sudo systemctl start mongodb && sleep 5 \ cd /opt/parse-server-example && sleep 5 \ sudo screen npm start && sleep 5 \ sudo screen parse-dashboard --config config.json --allowInsecureHTTP=1 && sleep 5 \ 

    Create a systemd unit (file of the form [unit name] .service in the / etc / systemd / system / directory) with the following contents:

     [Unit] Description=[описание юнита] Requires=mongodb.service After=mongodb.service [Service] Type=oneshot RemainAfterExit=yes ExecStart=[полный путь до скрипта server-starter.sh] PIDFile=[путь до PID фалйа, чтоб systemd мог отслеживать состояние юнита, допустим, /tmp/server-starter.pid] [Install] WantedBy=multi-user.target 

    // if necessary, you can specify from which user to run the script (read the documentation for systemd) // you can also specify the directory from which the script will run (to remove the cd ... line cd ... from the script) - also read the documentation

    Then we create the server-starter.sh script, the contents:

     #!/bin/bash cd /opt/parse-server-example screen npm start && sleep 5 screen parse-dashboard --config config.json --allowInsecureHTTP=1 

    Making it executable ( chmod +x server-starter.sh )

    Then we add mongodb and our unit to autorun:

     systemctl enable mongodb systemctl enable [имя юнита] 

    Now the script will run strictly after running mongodb almost without crutches at intervals. Repeat the similar actions for npm start (make a unit for it and after launching this unit launch the screen parse-dashboard... )

        echo -e "1"; sleep 2&& echo -e "2=="; sleep 2&& echo -e "eee" 

      but it's easier to write a script for /etc/init.d and run it there.