Script not running at startup


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Script not running at startup
# 1  
Old 02-13-2019
Script not running at startup

I am having check.sh script and check.service which I include to /etc/systemd/system/

Code:
chmod 744 /usr/local/bin/check.sh
chmod 664 /etc/systemd/system/check.service
systemctl daemon-reload
systemctl enable check.service

Code:
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?

Linux is 18.04 Ubuntu

Last edited by RudiC; 02-13-2019 at 10:29 AM..
# 2  
Old 02-13-2019
You may have better results if you use the full path of this command in your script:

Code:
/your/full/path/to/this/bin/websockify

# 3  
Old 02-13-2019
Check/Show file contents of ...
Code:
/etc/systemd/system/check.service

Check/Show output of...
Code:
systemctl status check.service


Last edited by stomp; 02-13-2019 at 11:23 AM..
# 4  
Old 02-13-2019
Quote:
Originally Posted by stomp
Check/Show file contents of ...
Code:
/etc/systemd/system/check.service

Check/Show output of...
Code:
systemctl status check.service

Code:
 /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.

This is systemd check file
Code:
[Unit]
After network.target = auditd.service

[Service]
ExecStart= /usr/local/bin/check.sh

[Install]
WantedBy = multi-user.target

--- Post updated at 01:07 PM ---

Quote:
Originally Posted by Neo
You may have better results if you use the full path of this command in your script:

Code:
/your/full/path/to/this/bin/websockify

tried, and nothing happend, ports are closed, only when put in terminal its gonna run

Code:
ss -an |grep 7000
ss -an |grep 5555


Last edited by RudiC; 02-13-2019 at 05:36 PM..
# 5  
Old 02-13-2019
You did execute the unit file. That does not work. It's not a script.

a) Change your unit file to:
Code:
[Unit]
After=network.target

[Service]
ExecStart=/usr/local/bin/check.sh
Type=simple

[Install]
WantedBy=multi-user.target

b) Change your script(check.sh)

Code:
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.

Last edited by stomp; 02-13-2019 at 02:47 PM..
# 6  
Old 02-13-2019
Quote:
Originally Posted by stomp
You did execute the unit file. That does not work. It's not a script.

a) Change your unit file to:
Code:
[Unit]
After=network.target

[Service]
ExecStart=/usr/local/bin/check.sh
Type=simple

[Install]
WantedBy=multi-user.target

b) Change your script(check.sh)

Code:
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.
Thanks for it, now it seems its ok a part of it. Port 5555 is listening but 7000 not.

Code:
-- Reboot --
ั„ะตะฑ 13 20:11:24 kladionica systemd[1]: Started check.service.
ั„ะตะฑ 13 20:11:39 kladionica check.sh[583]: WebSocket server settings:
ั„ะตะฑ 13 20:11:39 kladionica check.sh[583]:   - Listen on :5555
ั„ะตะฑ 13 20:11:39 kladionica check.sh[583]:   - Flash security policy server
ั„ะตะฑ 13 20:11:39 kladionica check.sh[583]:   - No SSL/TLS support (no cert file)
ั„ะตะฑ 13 20:11:39 kladionica check.sh[583]:   - proxying from :5555 to localhost:7000

this is a last line of .sh file, it seems ok when I put it like this in terminal
Code:
/usr/bin/socat -u TCP-LISTEN:7000,fork,reuseaddr,bind=127.0.0.1 SYSTEM:"lp -d MYPRNT $1"

Moderator's Comments:
Mod Comment Please use CODE tags (not QUOTE tags) when displaying sample input, output, and code segments.

Last edited by Don Cragun; 02-13-2019 at 04:09 PM..
# 7  
Old 02-14-2019
Code:
/path/to/websockify 5555 localhost:7000

I thought port 7000 was reserved for afs3 fileserver...
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Startup script

I can't quite find a clear answer on how to properly write a start up script. Does anybody have any ideas?? (3 Replies)
Discussion started by: Huitzilopochtli
3 Replies

2. Shell Programming and Scripting

Apache tomcat startup script not booting at startup.

I copied the script from an AskUbuntu post - #!/bin/bash ### BEGIN INIT INFO # Provides: tomcat7 # Required-Start: $network # Required-Stop: $network # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start/Stop Tomcat server ### END INIT INFO ... (14 Replies)
Discussion started by: Hijanoqu
14 Replies

3. Shell Programming and Scripting

Perl cisco copy running to startup

Hi all, i have a small simple perl that i cant make it work it is really stupid but i cant find solution and i needed fast. im trying to copy running to startup on a cisco router and show me the output like is ok Destination filename ? Building configuration... so the code i have is ... (0 Replies)
Discussion started by: IvanMP
0 Replies

4. Red Hat

running my own script during startup

Hi, I am using scientific linux with is a red hat cloning. I have written a script and I want it to be run during startup before the user log in. How do I do that? I know that there is some connection to the run level and the directory /etc/rc.d. But I don't know how exactly to do it ?... (4 Replies)
Discussion started by: programAngel
4 Replies

5. AIX

startup script

Hi I need the below script to be started whenever I reboot my aix server ? #cat cdbegin /cdirect/cdunix/ndm/bin/cdpmgr -i /cdirect/cdunix/ndm/cfg/cbspsdb01/initparm.cfg Please suggest how to add this to the startup ? (2 Replies)
Discussion started by: samsungsamsung
2 Replies

6. AIX

running fsck on aix in startup

Hi, I would like to know in which file I can get the option of enabling/disabling of running fsck on particular file system. As I know in /etc/filesystems these parameter should be there just like in Linux /etc/fstab I have created file system aix test but unable to find the option of... (1 Reply)
Discussion started by: manoj.solaris
1 Replies

7. Solaris

stop solaris 8 sendmail from running on startup

sorry i got this already... (3 Replies)
Discussion started by: itik
3 Replies

8. Shell Programming and Scripting

Running a Cron Script only @ Startup Pls Help!!

Hi friends i have a script "backup.sh" which is stored in "/var/lib/pgsql" directory. I want it to run as a cron so that it executes every time the system starts. I tried the follwing method I logged in as the root user and typed "crontab -e" The file was completly blank so i put the... (3 Replies)
Discussion started by: perk_bud
3 Replies

9. Shell Programming and Scripting

Startup script

New in Unix, I am adding a line "route add 57.14.y.y 57.14.x.x" every day after rebooting the system. Where can I add the line so during boot up (the system is re-started every day by design (???) the line is executed? (I tried the /etc/rc2.d/S90 but for some reason the line needs to be added... (2 Replies)
Discussion started by: texaspanama
2 Replies
Login or Register to Ask a Question