check.sh:
websockify 5555 localhost:7000 &
date > /home/john/date.txt
websockify is installed correctly and when I run this only in terminal it is good, but script not run this part on startup. I put a test date to export to file and this line is ok, but why first isn't?
/etc/systemd/system/check.service
/etc/systemd/system/check.service: line 1: [Unit]: command not found
/etc/systemd/system/check.service: line 2: After: command not found
/etc/systemd/system/check.service: line 4: [Service]: command not found
/etc/systemd/system/check.service: line 7: [Install]: command not found
/etc/systemd/system/check.service: line 8: WantedBy: command not found
root@test:~# WebSocket server settings:
- Listen on :5555
- Flash security policy server
- No SSL/TLS support (no cert file)
- proxying from :5555 to localhost:7000
root@test:~# systemctl status check.service
�- check.service
Loaded: loaded (/etc/systemd/system/check.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Wed 2019-02-13 18:55:47 CET; 47s ago
Process: 1489 ExecStart=/usr/local/bin/check.sh (code=exited, status=0/SUCCESS)
Main PID: 1489 (code=exited, status=0/SUCCESS)
феб 13 18:55:47test systemd[1]: Started check.service.
date > /home/john/date.txt
/path/to/websockify 5555 localhost:7000
Don't sent websockify to background, let it run in foreground. Both is possible, but letting it run in foreground is simpler. Run the tests before websockify not after. (tests are not needed really needed anyway, you have systemctl status ). You may add set -x to the start of your script to see what's being run with systemctl status. (or journalctl -u check.service )
You may add debug command line options to the websockify call. Anything that is printed on stdout will be in the log you get with systemctl status / journalctl.
well because when you run a script in batch mode e.g. using cron or init you are using utilities with minimalist intelligence e.g. like PATH=/bin:/usr/bin
In other words when you log in you have access to an environment, which is unknown in batch mode
The most important when it works in interactive and not in batch is to start with PATH variable:
put in your script at the beginning the path you have when you type env
If that doesnt work source your .profile or whatever you use as first line of your script knowing that it will generate loads of errors because not in interactive mode ( all things to do with stty to start with...) and see if that works, if so you are to search what in your env is needed to get your script to work...
Good luck