LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-02-2014, 03:49 PM   #1
kaza
Member
 
Registered: Apr 2010
Distribution: FC17
Posts: 278

Rep: Reputation: 2
Attempting to add a custom script to run at boot (FC19)


Hello,

I'm attempting to add a custom script to run at boot time
(as root) by using the systemd services (as per explanation
at "http://docs.fedoraproject.org/en-US/Fedora/19/html/Installation_Guide/s1-boot-init-shutdown-run-boot.html").

I created the file

/lib/systemd/system/ka_setup_tty.service

with the contents:

Code:
[Unit]
Description=A service that executes a user script on startup (setting up /dev/ttyS0).
Wants=network.target


[Service]
ExecStart=/root/bin/setup_ttyS0_for_ka
Type=oneshot

[Install]
WantedBy=multi-user.target
Then I created the script /root/bin/setup_ttyS0_for_ka
with contents:

Code:
#!/bin/tcsh


chmod o+rw /dev/ttyS0

stty -F /dev/ttyS0 19200
(I'm building some hardware than uses RS-232 interface
and I want to save me the repeated action of changing the ttyS0
parameters as a root each time I turn the PC on and start
working, I would like the setup to be done during the boot time.)

I checked that running the "/root/bin/setup_ttyS0_for_ka"
as a root does what I need but when I reboot, I see that
nothing changed in the ttyS0 setup, therefore the script didn't
run (successfully). Did I made an error with

"Wants=network.target"

or

"WantedBy=multi-user.target"?

I just left these lines as in example.
What service sets up all the serial ports, maybe I need to
wait for its end?
Am I right assuming that when "systemd" parses the "*.service"
files and executes what's in them, it runs as "root"?

Does anyone sees something obvious I forgot?

TIA for any ideas,
 
Old 05-03-2014, 04:30 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3592Reputation: 3592Reputation: 3592Reputation: 3592Reputation: 3592Reputation: 3592Reputation: 3592Reputation: 3592Reputation: 3592Reputation: 3592Reputation: 3592
Not the right answer (I remember adding services to Systemd but I kind of forgot what it took ;-p) would it be easier to just enable the "rc.local" service and add your commands to /etc/rc.d/rc.local? Or add / edit a udev rule with these commands to be run as soon as /dev/ttyS0 becomes available?
 
Old 05-04-2014, 03:54 PM   #3
vl23
Member
 
Registered: Mar 2009
Posts: 125

Rep: Reputation: 8
use an udev rule to modify the device file ownership, as it is a tty the logind service is probably screwing with it also, and you might want to check out its config since it is responsible for things like VTs and ttys, I have no idea since my knowledge of that piece of garbage is limited.
Why not try Slack or Sabayon, they are sensible distros that do not have init systems which do stuff you do not want or need?
 
Old 05-04-2014, 07:46 PM   #4
DJ Shaji
Member
 
Registered: Dec 2004
Location: Yo Momma's house
Distribution: Fedora Rawhide, ArchLinux
Posts: 517
Blog Entries: 15

Rep: Reputation: 106Reputation: 106
Generally speaking, rc.local is executed at the very end of the boot process. It should be the simplest way to run a command you would be running by hand every time you boot up the system.
 
Old 05-05-2014, 09:44 AM   #5
kaza
Member
 
Registered: Apr 2010
Distribution: FC17
Posts: 278

Original Poster
Rep: Reputation: 2
Hi, thanks for they replyes!

I created the file

/etc/rc.d/rc.local

with the following contents:

Code:
#!/bin/tcsh

setup_ttyS0_for_ka
(the directory of that script is in the "path"),
changed its permissions to be executed by "root":

Code:
<root localhost.localdomain>.../root>ls /etc/rc.d/rc.local
-rwxr--r--. 1 root root 35 May  5 17:20 /etc/rc.d/rc.local
rebooted ... and nothing, still the permissions and baud rate of ttyS0
are default and not as they are after running the "setup_ttyS0_for_ka" script.

What else I forgot?
 
Old 05-05-2014, 09:57 AM   #6
kaza
Member
 
Registered: Apr 2010
Distribution: FC17
Posts: 278

Original Poster
Rep: Reputation: 2
Solved!

After thinking that relying on "path" might be too early
in the boot process, I changed the reference to the script
to be a full path:

/root/bin/setup_ttyS0_for_ka

, rebooted - and now it works.

Thanks for the help!

Now I have to try remembering how to mark the thread as "solved"...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] custom run script for dosbox? dwmolyneux Linux - Software 4 06-24-2018 12:40 AM
[SOLVED] Attempting to upgrade FC17 to FC19 using fedup kaza Fedora 18 09-30-2013 02:53 AM
Run custom boot script from a network server? cantab Ubuntu 1 06-16-2010 10:26 AM
run custom script at boot time on IPcop lothario Linux - Networking 1 06-24-2008 08:54 PM
Is a script, run at boot time from init.d, run with root authority? tmbrwolf53 Linux - Server 2 03-31-2007 08:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration