Bosse_B
Posts: 922
Joined: Thu Jan 30, 2014 9:53 am

Jessie: How to run a script AFTER boot is done?

Fri Oct 02, 2015 4:38 pm

I need to run a user level script to start VNC server directly after boot.
The old init.d scripting does not work anymore on Jessie, so I have to figure out a different way not involving a manual login via PuTTY to launch the server.
I do have a vnc.sh script in the pi home directory which if executed will start the VNC server.
It contains this:

Code: Select all

#!/bin/sh
vncserver :1 -geometry 1280x900 -depth 24 -dpi 96
It starts the server on port #5901 and after it has been run manually all is fine.
But I would rather have it done automatically upon boot....
Is there any way to detect that boot is done and launch it?
Bo Berglund
Sweden

Bosse_B
Posts: 922
Joined: Thu Jan 30, 2014 9:53 am

Re: Jessie: How to run a script AFTER boot is done?

Sat Oct 03, 2015 10:03 am

I reverted to Raspbian Wheezy 2015-05-05 and all is now working fine including VNC on boot.
I think Jessie is a bit too new for everything to work.
Bo Berglund
Sweden

hippy
Posts: 6853
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Jessie: How to run a script AFTER boot is done?

Sat Oct 03, 2015 11:40 am

Bosse_B wrote:I think Jessie is a bit too new for everything to work.
I would say it's more that systemd is unfamiliar to most Pi users so they do not yet know how to do things 'the systemd way'. There will inevitably be some teething problems but I have every confidence the Raspberry team will do all they can to quickly resolve those.

I expect "How to run things after boot-up" will become a quite common question. I am currently trying to figure that out myself and it is more complicated than 'just add this line to this file'.

If /etc/rc.local is no longer the last thing run at boot-up, then it might be an idea for Rasbian to add an /etc/rc.booted ( or similar ) which is the last thing run. That way those unfamiliar with systemd can add commands and calls to shell scripts in there without having to worry about systemd per se. That might not be the best way to do things, but it would provide an easy to use, easier to explain solution.

User avatar
kusti8
Posts: 3439
Joined: Sat Dec 21, 2013 5:29 pm
Location: USA

Re: Jessie: How to run a script AFTER boot is done?

Sat Oct 03, 2015 12:01 pm

The current workaround is to add a sleep 10 into rc.local so that it starts you program last. It's not elegant but it works.
There are 10 types of people: those who understand binary and those who don't.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Jessie: How to run a script AFTER boot is done?

Sat Oct 03, 2015 1:38 pm

It will work once you do the obvious step of uninstalling systemd.

I assume that the next release of Jessie will have that step done already for you.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6195
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: Jessie: How to run a script AFTER boot is done?

Sat Oct 03, 2015 1:45 pm

Joe Schmoe wrote:I assume that the next release of Jessie will have that step done already for you.
Absolutely not.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Jessie: How to run a script AFTER boot is done?

Sat Oct 03, 2015 2:09 pm

ShiftPlusOne wrote:
Joe Schmoe wrote:I assume that the next release of Jessie will have that step done already for you.
Absolutely not.
Eventually, it will. Maybe not in the next release.

In the meantime, we can expect a lot of threads like this one and others like it. I guess that'll keep us advice-givers busy.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

gkreidl
Posts: 6222
Joined: Thu Jan 26, 2012 1:07 pm
Location: Germany

Re: Jessie: How to run a script AFTER boot is done?

Sat Oct 03, 2015 4:01 pm

Joe Schmoe wrote:It will work once you do the obvious step of uninstalling systemd.

I assume that the next release of Jessie will have that step done already for you.
You've already been part of a flame war against systemd in the past and now you're starting the same rubbish again. You should change your signature to "I'm only here to make trouble". That would be honest at least.
Minimal Kiosk Browser (kweb)
Slim, fast webkit browser with support for audio+video+playlists+youtube+pdf+download
Optional fullscreen kiosk mode and command interface for embedded applications
Includes omxplayerGUI, an X front end for omxplayer

User avatar
DougieLawson
Posts: 37701
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Jessie: How to run a script AFTER boot is done?

Sat Oct 03, 2015 4:49 pm

Joe Schmoe wrote:
ShiftPlusOne wrote:
Joe Schmoe wrote:I assume that the next release of Jessie will have that step done already for you.
Absolutely not.
Eventually, it will. Maybe not in the next release.

In the meantime, we can expect a lot of threads like this one and others like it. I guess that'll keep us advice-givers busy.
You're wrong!

I've had two RPis running Jessie for months and had no end of problems. During this week I migrated my most important machine to Jessie (first one to get rebooted when I got home last night). Yesterday/this morning I've migrated another three machines. I've left my machine running with a Wolfson sound card on Raspbian and one other which is running an old copy of NOOBS (those two haven't beem booted for 118 days) that wasn't built by me.

I have to say I think the Raspberry Pi Foundation folks who've spent the last six months working on getting Jessie ready for the general population have done a superb job and there's no way I'm going to rip systemd out. It's going to take a while to learn it but after all the migration work it appears to be much more stable than sysvinit.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Jessie: How to run a script AFTER boot is done?

Sat Oct 03, 2015 4:56 pm

So, you're saying that systemd used to be a pain in the neck (your words: "No end of problems"), but now you've learned enough about its quirks that you can tolerate it.

Good for you. I am impressed.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

Bosse_B
Posts: 922
Joined: Thu Jan 30, 2014 9:53 am

Re: Jessie: How to run a script AFTER boot is done?

Sat Oct 03, 2015 5:17 pm

DougieLawson wrote: I've had two RPis running Jessie for months and had no end of problems.
....
I have to say I think the Raspberry Pi Foundation folks who've spent the last six months working on getting Jessie ready for the general population have done a superb job and there's no way I'm going to rip systemd out. It's going to take a while to learn it but after all the migration work it appears to be much more stable than sysvinit.
I am a bit confused by your statement that you have had no end of problems with the Pi:s running Jessie and yet you compliment the Foundation crew for Jessie...
Is this actually what you mean? (Lots of problems, but it is good).

I (thread starter) have only limited exposure to Jessie but my first impressions were good. Very fast boot and initially booting to the desktop rather than to RaspiConfig is also a boon, even though I got confused since I am accustomed to the RaspiConfig for all Pi:s I built so far.

Unfortunately I had to abandon Jessie due to two issues:
1) Inability to start VNC service during boot
2) Could not install Free-Pascal on Jessie (no apt-get, I tried to do it from sources)

Backed off to Wheezy and both tasks accomplished without a glitch.

But I guess Jessie is the future anyway, so it means that "someone" will iron out the wrinkles and then it will be a good distribution.
Bo Berglund
Sweden

User avatar
DougieLawson
Posts: 37701
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Jessie: How to run a script AFTER boot is done?

Sat Oct 03, 2015 5:39 pm

I've been running Jessie for 18months (and more). It's been unstable at times, so much so that when I built my B+ on Jessie it had to be reverted to Wheezy before it went online 24/7 on the internet.

The last six months hard work has fixed all of the problems I've had with Jessie. The last bug being one with NFS not being unmounted before the network interface was disabled which caused reboots to hang.

The systemd detractors need to shut up and stop telling folks to rip systemd out of their systems. Because of the hard work by folks including Plugwash and ShiftPlusOne who've built a new Raspbian we have a good OS that is ready to release to ALL Raspberry Pi users.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Jessie: How to run a script AFTER boot is done?

Sat Oct 03, 2015 5:58 pm

IOW, Dougie used to be a rational guy, but now he's drunk the Kool Aid.

That's the takeaway of his recent posts.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

User avatar
rpdom
Posts: 16376
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Jessie: How to run a script AFTER boot is done?

Sat Oct 03, 2015 6:43 pm

Although I have so far removed systemd from most of my Jessie systems, I can see that it might have some advantages if configured properly. Therefore I will work on learning how to tame the beast and see how many of my systems I can get converted over.

It won't be all of them. I've tried moving my main laptop to jessie on a few occasions and it is unusable :(

jbernardo
Posts: 6
Joined: Sat Apr 04, 2015 6:16 am

Re: Jessie: How to run a script AFTER boot is done?

Sat Oct 03, 2015 6:51 pm

DougieLawson wrote:The systemd detractors need to shut up and stop telling folks to rip systemd out of their systems.
And unfortunately, this is why I stopped trying to have a rational argument with systemd defenders. It always ends like this.
Mit der Dummheit kämpfen Götter selbst vergebens.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Jessie: How to run a script AFTER boot is done?

Sat Oct 03, 2015 6:56 pm

jbernardo wrote:
DougieLawson wrote:The systemd detractors need to shut up and stop telling folks to rip systemd out of their systems.
And unfortunately, this is why I stopped trying to have a rational argument with systemd defenders. It always ends like this.
Indeed.

It always boils down to:

Sit down, shut up.
Get on the bus.
Drink the Kool Aid.

Never any defense for it (because there is none) - always "It's the future, get used to it."

The point is: If we wanted to be with the crowd (which, don't get me wrong, has advantages for many people/users - it is the way to go if your goal is to make money. As an old boss told me (in all seriousness), "Don't buck trends"), we'd stick with Windows.

We like Linux because it allows us to do our own thing. To do things based on merit and personal choice, not on crowd-psych.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

User avatar
DougieLawson
Posts: 37701
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Jessie: How to run a script AFTER boot is done?

Sat Oct 03, 2015 7:00 pm

If it isn't the future why has every major Linux distro dropped sysvinit and adopted systemd rather than upstart?
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Jessie: How to run a script AFTER boot is done?

Sat Oct 03, 2015 7:05 pm

DougieLawson wrote:If it isn't the future why has every major Linux distro dropped sysvinit and adopted systemd rather than upstart?
I don't deny that it is the future. I just reject the notion that anyone (i.e., anyone lacking the crowd mentality) should accept that as a reason to use it. As I said, if we had that mentality, we'd stick with Windows.

Essentially, I am saying that Linux-think is being molded by TPTB to resemble Windows-think, and I don't like it.

I also hated upstart, BTW. Not sure why you mentioned that.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12665
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Jessie: How to run a script AFTER boot is done?

Sat Oct 03, 2015 7:48 pm

Joe Schmoe, please tone it down a bit.

As for systemd dislikers, in my humble opinion you dislike it just because you don't understand it, so are scared of it.
It seems however to bring much needed progress, so please leave your dislike at home...
Rather than complain about bugs and issues, please help resolve them.
You will never be able to revert the trend to using systemd, so better get along with it.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: Jessie: How to run a script AFTER boot is done?

Sat Oct 03, 2015 7:57 pm

mahjongg wrote:J
You will never be able to revert the trend to using systemd, so better get along with it.
IOW,
sit down shut up get on the bus drink the kool aid

I personally will never use systemd, and I won't stop advising others to do likewise.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12665
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Jessie: How to run a script AFTER boot is done?

Sat Oct 03, 2015 8:16 pm

sit down shut up get on the bus drink the kool aid
didn't ask you that, just to be a bit calmer and more rational, and not to rant about your dislikes so much, and not be so offensive toward other posters here.
IOW "be nice". :P

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6195
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: Jessie: How to run a script AFTER boot is done?

Sun Oct 04, 2015 4:15 pm

Cleared the thread of junk irrelevant to the OP's post.

If you want to argue about systemd, start your own thread. That's perfectly fine and allowed. Just be respectful if you do.

hippy
Posts: 6853
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Jessie: How to run a script AFTER boot is done?

Sun Oct 04, 2015 6:02 pm

Having accepted that systemd is here, and accepting things have to be made to work with it, I decided to try and figure it out for myself.

I have got some way there which may help others trying to do the same, but I would appreciate some help and feedback from those more experienced with Linux and particularly with systemd experience.

This was the process I used. Files might not be in preferred places but it does at least work. I used upper-case just so things would stand out more amongst the systemd messages.

The first step was to get something to simply run under systemd which can be tweaked later to work as desired.

Create a shell script to run after boot-up. This will just output the date and time, put the same in a text file, and output a message to show that it is running ...

Code: Select all

sudo mkdir /etc/booted
sudo nano /etc/booted/booted.sh
  #!/bin/sh -e
  date > /booted.txt
  date
  echo "\n\nINSIDE BOOTED.SH\n\n"
  exit 0
sudo chmod +x booted.sh
We also need to create a unit file so systemd can do its thing. We do not particularly care where in the process things are run, only that they are, so "After=syslog.target" and "WantedBy=multi-user.target" are just 'best guesses' for now ...

Code: Select all

sudo nano /etc/systemd/system/booted.service
  [Unit]
  Description=SCRIPT TO RUN AFTER BOOTING
  After=syslog.target
  [Service]
  ExecStart=/etc/booted/booted.sh
  Type=oneshot
  [Install]
  WantedBy=multi-user.target  
Now we have to let systemd know about the added booted.service, and we need to enable that to be run when booted. And then we can reboot to see what happens. Note it's systemctl, C-T-L not systemctrl ...

Code: Select all

sudo systemctl daemon-reload
sudo systemctl enable booted.service
sudo reboot
And in the midst of all the boot-up messages we see "Starting SCRIPT TO RUN AFTER BOOTING..." and "[OK] Started SCRIPT TO RUN AFTER BOOTING",but no date and no echoed "INSIDE BOOTED.SH" which should be shown when the booted.sh script runs.[SOLVED]

Logging in and /booted.txt has been created and is as expected which shows booted.sh did run, and "sudo systemctl -l booted.service" shows ...

Code: Select all

booted.service - SCRIPT TO RUN AFTER BOOTING
   Loaded: loaded (/etc/systemd/system/booted.service; enabled)
   Active: inactive (dead) since Sun 2015-10-04 18:32:37 BST; 6min ago
  Process: 482 ExecStart=/etc/booted/booted.sh (code=exited, status=0/SUCCESS)
 Main PID: 482 (code=exited, status=0/SUCCESS)

Oct 04 18:32:34 raspberrypi booted.sh[482]: Sun  4 Oct 18:32:34 BST 2015
Oct 04 18:32:34 raspberrypi booted.sh[482]: INSIDE BOOTED.SH
Oct 04 18:32:37 raspberrypi systemd[1]: Started SCRIPT TO RUN AFTER BOOTING.
So the date and echoed messages are shown by that but they never made it to the TV screen systemd listed messages.

Anyone know what I need to do to make that happen ?
[SOLVED]

Also, if anyone knows what [Unit]Before=, [Unit]After= and [Install]WantedBy= settings should be to have something executing when systemd completes that would save me some researching and experimentation.

hippy
Posts: 6853
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Jessie: How to run a script AFTER boot is done?

Sun Oct 04, 2015 6:36 pm

To get echoed output to the TV screen at bootup you need to play with the [Service]StandardOutput= and [Service]StandardError= entries. Not sure they are entirely right but this gets the output on screen ...

Code: Select all

sudo nano /etc/systemd/system/booted.service
  [Unit]
  Description=SCRIPT TO RUN AFTER BOOTING
  After=syslog.target
  [Service]
  ExecStart=/etc/booted/booted.sh
  Type=oneshot
  StandardOutput=syslog+console
  StandardError=syslog+console
  [Install]
  WantedBy=multi-user.target  

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6195
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: Jessie: How to run a script AFTER boot is done?

Sun Oct 04, 2015 6:52 pm

hippy wrote:Not sure they are entirely right but this gets the output on screen
The way we've done it for rc.local is to add an override file with the following content:

Code: Select all

[Service]
StandardOutput=tty
If you add that to your booted.service, that should do it too.

Return to “Raspbian”