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... )
sleep 1after each command. - aleks.andr