0

I am trying to start a service in ubuntu 16.04. And wrote this .service file

[Unit]
Description=Executing during boot

[Service]
Type=forking
ExecStart=/home/lokesh/Documents/script.sh
TimeoutSec=30
Restart=on-failure
RestartSec=30
StartLimitInterval=350
StartLimitBurst=10

[Install]
WantedBy=multi-user.target
Alias=startUp.service

Added this service file to /etc/systemd/system/ And this is script file, so basically I am trying to execute a simple operation to write to a file

#!/bin/sh
echo "I'm feeling good" >> txt
echo "how are you" >> txt 

Before restart I tested the script file it is working and producing a txt file with some texts in it. And then followed these steps:

chmod u+x /path/to/script/script.sh
sudo systemctl start startUp.service
sudo systemctl stop startUp.service
sudo systemctl enable startUp.service

But after reboot I am supposed to get a new file named txt with few texts. But I am unable to get the output. Is it happening because service is not started or else there is something wrong with service file or script file ?

Regards

4
  • 2
    I think you need to enter the full path where txt needs to be created. So as per your example /home/lokesh/Documents/txt. I would not be surprised if the file txt is to be found in /root, assuming your service does start.
    – user680858
    Nov 22, 2017 at 13:12
  • 2
    it needs to be in script file like this echo "I'm feeling good" >> /home/lokesh/Documents/txt right ? Nov 22, 2017 at 13:15
  • @WillemK Damn!! thanks man it worked so stupid of me not to pass the file path Nov 22, 2017 at 13:24
  • @willemk please post an answer on that, great work! Nov 22, 2017 at 13:27

1 Answer 1

0

Any program, script or service that starts during boot time only has a limited environment. Therefor you must always use full path names.
In this case you need to enter the full path where txt needs to be created. So as per your example:

/home/lokesh/Documents/txt

I would not be surprised if the file txt is to be found in /root, assuming your service does start

3
  • No I couldn't see txt in /root yes the service was starting. Nov 23, 2017 at 3:51
  • if you really need to know where txt is from the time you did not use full path, I suppose you could do a sudo find / -name txt.
    – user680858
    Nov 23, 2017 at 23:58
  • Thank you I am just learning about systemd. I am having another problem over here askubuntu.com/questions/979353/… . So basically I want to start an activation service after starting network service Nov 24, 2017 at 2:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .