LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 10-18-2017, 09:32 AM   #1
bravored
Member
 
Registered: Mar 2005
Distribution: RHEL, freeBSD, Solaris
Posts: 49

Rep: Reputation: 0
rhel7 - systemd : StartUp Script


Hello
I created a startup script in rhel7 however the sym links are not in the run level ( /etc/rc3.d/ /etc/rc4.d/ etc)

I see its enabled :
systemctl list-unit-files | grep my1
my1.service enabled
Shows as enabled

Also how do I delete the my1 from the list, I know you can mask it but is there a del option? chkconfig --del my equivalent to systemctl ?

Thanks
 
Old 10-18-2017, 11:17 AM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by bravored View Post
I created a startup script in rhel7 however the sym links are not in the run level ( /etc/rc3.d/ /etc/rc4.d/ etc)
this has nothing to do with systemd, it's the old init system (sysvinit iirc).

you MUST learn systemd!!!

Quote:
I see its enabled :
systemctl list-unit-files | grep my1
my1.service enabled
Shows as enabled

Also how do I delete the my1 from the list, I know you can mask it but is there a del option? chkconfig --del my equivalent to systemctl ?
Code:
systemctl disable my1
systemctl stop my1
 
Old 10-18-2017, 11:54 AM   #3
bravored
Member
 
Registered: Mar 2005
Distribution: RHEL, freeBSD, Solaris
Posts: 49

Original Poster
Rep: Reputation: 0
Great !
But what the help here for my ask?

Like I said ; I see it as enabled however when I restart I dont see the service running/active state.
That is my main issue.
 
Old 10-18-2017, 12:05 PM   #4
bravored
Member
 
Registered: Mar 2005
Distribution: RHEL, freeBSD, Solaris
Posts: 49

Original Poster
Rep: Reputation: 0
Lets take an example: test.service
# systemctl status test.service
● test.service - Test sample script
Loaded: loaded (/etc/systemd/system/test.service; enabled; vendor preset: disabled)
Active: inactive (dead) since Wed 2017-10-18 11:46:35 EDT; 1h 9min ago
Process: 1339 ExecStart=/var/tmp/test_script.sh (code=exited, status=0/SUCCESS)
Main PID: 1339 (code=exited, status=0/SUCCESS)

The service file:
#cat /etc/systemd/system/test.service
[Unit]
Description=Test sample script
After=network.target

[Service]
Type=simple
ExecStart=/var/tmp/test_script.sh
TimeoutStartSec=0
user=root

[Install]
WantedBy=default.target

The script:
#cat /var/tmp/test_script.sh
#!/bin/bash
echo "This is a sample script to test auto run during boot" > /var/tmp/script.out
echo "The time the script run was --> `date`" >> /var/tmp/script.out

The perms:
# ls -l /var/tmp/test_script.sh
-rwx------. 1 root root 164 Oct 18 11:41 /var/tmp/test_script.sh

Enabled:
# systemctl is-enabled test.service
enabled
# ls -l /etc/systemd/system/default.target.wants/test.service
lrwxrwxrwx. 1 root root 32 Oct 18 13:04 /etc/systemd/system/default.target.wants/test.service -> /etc/systemd/system/test.service


# systemctl is-active test.service
inactive
 
Old 10-18-2017, 04:35 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
Did your output file (/var/tmp/script.out) get created and contain the desired information?

Since the script is not a real daemon or service it isn't going to continuously run.
 
Old 10-19-2017, 09:22 AM   #6
bravored
Member
 
Registered: Mar 2005
Distribution: RHEL, freeBSD, Solaris
Posts: 49

Original Poster
Rep: Reputation: 0
Hey Michaelk
Ok the output did get written to it at boot.
 
Old 10-19-2017, 09:30 AM   #7
bravored
Member
 
Registered: Mar 2005
Distribution: RHEL, freeBSD, Solaris
Posts: 49

Original Poster
Rep: Reputation: 0
Ok so I another script with start,stop case statements
Updated the systemStatus.sh.service file
Ran the systemctl reenable systemStatus

However when I checked sysstat.service its in these 2 locations:

/sys/fs/cgroup/devices/system.slice/sysstat.service
/sys/fs/cgroup/systemd/system.slice/sysstat.service

When I check the service I created its not the locations as sysstat.service , sshd.service etc are in
# find / -name systemStatus.sh.service
/etc/systemd/system/default.target.wants/systemStatus.sh.service
/etc/systemd/system/systemStatus.sh.service

Also ran a reboot

I am not sure if its the placement of the service file or the file name itself the cause. (Will try it out)
Or the variables in the file

The startus service unit file
[Unit]
Description=systemStatus script
After=network.target

[Service]
ExecStart=/var/tmp/systemStatus.sh start
ExecStop=/var/tmp/systemStatus.sh stop

[Install]
WantedBy=default.target
 
Old 10-20-2017, 09:29 AM   #8
bravored
Member
 
Registered: Mar 2005
Distribution: RHEL, freeBSD, Solaris
Posts: 49

Original Poster
Rep: Reputation: 0
I got it work in lab! yay!

Added to the following service file
RemainAfterExit=yes

Ran systemctl daemon-reload "service file" << no quotes ; at this point you can systemctl restart service; systemctl reenable service
(Since it isnt prod I decided to reboot to see if the service is online after reboot -- viola! it did)

During trial period I had used: type=simple, type=oneshot, type=forking(sshd had this)
I also used user=root -- none of them mattered.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: How to automatically execute shell script at startup boot on systemd Linux LXer Syndicated Linux News 0 07-07-2016 10:21 AM
Can't access full journalctl from script via systemd service even though user is in systemd-journal group iwtbf Linux - Newbie 0 02-19-2016 02:44 PM
[SOLVED] Fedora 17 systemd - how to get a startup script to execute? rylan76 Fedora 12 12-10-2014 01:45 AM
systemd startup script fails v3ct0r Linux - Newbie 5 03-04-2014 08:15 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 07:16 PM.

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