Getting Shell script to start java app on boot

Hello,

I have been struggling with a .sh file that works when executed but I can’t get it to launch an application at boot. I have tried

sh ./crushftp_init.sh
and also creating a symbolic link and copying the script to init.d

I am afraid I am confused as last time I did this linux was using sysv which worked once I had the service showing up under the chkconfig -list

Systemd is confusing to me. I am not sure what the process is. I see the scripts are compatible with the LSB tags. I just don’t understand how to make systemd launch an application or it’s structure.

Hi
If it’s an init file, then you would need to add start to your command line;


./crushftp_init.sh start

If you post the script, it should be easy to create a crushftp.service file

My inelegant, quick workaround for this sort of thing is to place an “@reboot” entry in root’s crontab.

It still works exactly the same with systemd.

Ok I must have done something incorrectly if it’s the exact same. The script has changed though. Here is a sample.

http://pastebin.com/WH9rqkrr

Hi
So did you run the command with the start option?

If you copy the above file to the /etc/init.d/ directory and then try starting it, what happens?

Hey malcolmlewis thanks for your help.

So I copied the script to the /etc/init.d/ folder ran the install command:

sh ./crusftp_init.sh

Then used the installed script to launch the program. All works well with the script. There is a java process visible using top and the GUI is available as it should be.
I then rebooted the machine and it can confirm it doesn’t launch on boot.

In my init.d folder it may be a mess… I tried linking to the script.

http://pastebin.com/SudTJziH

Hi
OK, lets do some clean up and try starting it…


su -
cd /etc/init.d
rm crushftp crushftp_init.d
mv crushftp_init.sh crushftp
chmod 0700 crushftp
ln -s /etc/init.d/crushftp /usr/sbin/rccrushftp
rccrushftp start

I removed all the old stuff and placed the crushftp_init.sh script in /etc/init.d/crushftp
The link didn’t work. Wouldn’t I need to link soft link to the actual script not the containing folder? Also the program’s jar file is in /var/opt/Crushftp_7/
The rccrushftp link is where I am now lost. rccrushftp also hasn’t been installed yet as a service.
./crushftp_init.sh now works when I am in the correct folder ie /etc/init.d/crushftp/

Josh

Hi
So you now have a folder /etc/init.d/crushftp? and in that folder exists crushftp_init.sh and when you run;


./crushftp_init.sh start

It works as expected?

You continue to refer to /etc/init.d, but startup scripts are not run from /etc/init.d. And we have no idea what crusftp_init.sh does, nor why it had to be run from /etc/init.d.

So start with providing facts. Show output of “systemctl status crushftp.service”.

When I run ./crushftp_init.sh from the folder /etc/init.d/crushftp/ it works as expected correct.

What does the sh command do to a .sh file?

Josh

Hi
There is no crushftp.service file (yet…) nothing wrong with it there for the moment, it’s just a script, once the OP confirms it’s working as required, we can create a service file in /etc/systemd/system.

Hi
The .sh just tells the system what shell to use, but if you look at the first line in the script it has the ‘whole shebang’ #!/bin/sh which needs to change to #!/usr/bin/sh for openSUSE and is a softlink to /bin/bash anyway…

Anyway, can you move the script one directory up and see if it works;


cd /etc/init.d/crushftp/
mv crushftp_init.sh ../
./crushftp_init.sh start

Then can create a simple systemd service file for it.

Hi
So if it works as expected, we can create a simple service file for it as follows;


# /etc/systemd/system/crushftp.service
#

[Unit]
Description=CrushFTP Server service

[Service]
Type=simple
ExecStart=/usr/bin/sh -c "/etc/init.d/crushftp_init.sh start"
ExecStop=/usr/bin/sh -c "/etc/init.d/crushftp_init.sh stop"

[Install]
WantedBy=multi-user.target

So copy/paste the above into a file called crushftp.service and save this to /etc/systemd/system/

Then;


systemctl status crushftp.service
systemctl start crushftp.service
systemctl status crushftp.service

So it should show a working service?

Hey I used vi to edit a the service file and it seems ok. Do I need to chmod +x the resultant file?

When I check the status I get:

iisserver:/etc/systemd/system # systemctl status crushftp.service
crushftp.service - CrushFTP Server service
Loaded: loaded (/etc/systemd/system/crushftp.service; disabled)
Active: inactive (dead)

Apr 23 14:05:40 iisserver systemd[1]: Started crushftp.service.
Apr 23 14:05:40 iisserver sh[22195]: FAIL
Apr 23 14:05:40 iisserver systemd[1]: crushftp.service: main process exited, code=exited, status=1/FAILURE
Apr 23 14:05:40 iisserver systemd[1]: Unit crushftp.service entered failed state.
Apr 23 14:17:41 iisserver systemd[1]: Starting CrushFTP Server service…
Apr 23 14:17:41 iisserver systemd[1]: Started CrushFTP Server service.
Apr 23 14:18:21 iisserver systemd[1]: Starting CrushFTP Server service…
Apr 23 14:18:21 iisserver systemd[1]: Started CrushFTP Server service.
Apr 23 14:18:21 iisserver sh[22449]: Starting CrushFTP… OK
Apr 23 14:18:22 iisserver sh[22465]: Shutting down CrushFTP…OK

Not sure what I did wrong. I did move the init script to /etc/init.d/ before hand so the service file should be referencing the right location.

josh

EDITED! I had entered the text from your service template incorrectly. The first few times I tried to run the command it failed but now it starts and stops immediately!

Hi
OK
So what output do you see from;


systemctl start crushftp.service
journalctl -u crushftp.service

This is way more involved that the sysv installation I did last time. I managed to hack the LSB tags onto a script provided by another user and suse 11 kept on ticking. I upgraded to 12.1 and I am pretty sure it kept working the same way. Now this is much different. Systemd is a strange beast to me thank you for your help.

The server isn’t up as of writing this. Does the service file we wrote start and stop the server at once?

journalctl returns the below text.

-- Logs begin at Wed 2014-04-23 12:31:06 EDT, end at Wed 2014-04-23 14:23:53 EDT. --
Apr 23 14:05:29 iisserver systemd[1]: [/etc/systemd/system/crushftp.service:1] Assignment outside of section. Ignoring.
Apr 23 14:05:29 iisserver systemd[1]: [/etc/systemd/system/crushftp.service:2] Assignment outside of section. Ignoring.
Apr 23 14:05:40 iisserver systemd[1]: [/etc/systemd/system/crushftp.service:1] Assignment outside of section. Ignoring.
Apr 23 14:05:40 iisserver systemd[1]: [/etc/systemd/system/crushftp.service:2] Assignment outside of section. Ignoring.
Apr 23 14:05:40 iisserver systemd[1]: Starting crushftp.service...
Apr 23 14:05:40 iisserver systemd[1]: Started crushftp.service.
Apr 23 14:05:40 iisserver sh[22195]: FAIL
Apr 23 14:05:40 iisserver systemd[1]: crushftp.service: main process exited, code=exited, status=1/FAILURE
Apr 23 14:05:40 iisserver systemd[1]: Unit crushftp.service entered failed state.
Apr 23 14:17:41 iisserver systemd[1]: Starting CrushFTP Server service...
Apr 23 14:17:41 iisserver systemd[1]: Started CrushFTP Server service.
Apr 23 14:18:21 iisserver systemd[1]: Starting CrushFTP Server service...
Apr 23 14:18:21 iisserver systemd[1]: Started CrushFTP Server service.
Apr 23 14:18:21 iisserver sh[22449]: Starting CrushFTP... OK
Apr 23 14:18:22 iisserver sh[22465]: Shutting down CrushFTP...OK
Apr 23 14:23:53 iisserver systemd[1]: Starting CrushFTP Server service...
Apr 23 14:23:53 iisserver systemd[1]: Started CrushFTP Server service.
Apr 23 14:23:53 iisserver sh[22527]: Starting CrushFTP... OK
Apr 23 14:23:53 iisserver sh[22543]: Shutting down CrushFTP...OK


Do you guys know of a good book about linux that is complete but not thicker than all of the books of the bible, for someone of my ability. It is an artform that seems to require a lot of reading and practice, taming Linux. I keep getting flack from everyone that I am spending too much time on the internet and fiddling with the computer. I feel like I need to get more out of my readings.

BTW thanks again for all your help.

Hi
Well you could try removing the ExecStop line from the service file and see if that helps.

I would get onto the crushftp folks and see if they have created a crushftp.service file for systemd, else remove the one we created and just start it manually for the moment.

Do you have a download link to the application, will see if can get something working here.