Execute a script while boot up in RHEL7
Solution 1
Based on Redhat's documentation Creating Custom Unit Files and systemd.exec — Execution environment configuration:
Not tested™
Create the file (touch>chmod>edit seems recommended, I don't known why):
touch /etc/systemd/system/activefolder.service
chmod 664 /etc/systemd/system/activefolder.service
vim /etc/systemd/system/activefolder.service
/etc/systemd/system/activefolder.service
example:
[Unit]
Description=activefolder
After=network.target
[Service]
WorkingDirectory=/var/www/activefolder/current
ExecStart=/var/www/activefolder/current/script/delayed_job start
Type=forking
PIDFile=/run/activefolder.pid
Environment="RAILS_ENV=production"
#User=httpd
#Group=httpd
[Install]
WantedBy=default.target
Then:
systemctl daemon-reload
systemctl start name.service
Solution 2
You don't need to create a systemd service to run command at boot, it can be done with crontab
.
Just add the command you need to run with @reboot <user_name>
prefix to your /etc/crontab
In your case it would be:
@reboot root cd /var/www/activefolder/current && RAILS_ENV=production script/delayed_job start
Tested to work in CentOS 6/7 (requires vixie-cron
, might not work with cronie
)
Related videos on Youtube
Kavya shree
Updated on September 18, 2022Comments
-
Kavya shree over 1 year
I want to create a table in Redshift by adding columns of the other two tables.
Want to create new table on following conditions
- if table1.sid = table2.sid
then t1.totalcorrect+t2.totalcorrect, t1.totalquestions+t2.totalquestions. that is s4 to s7
- else data from both tables as it is
Using joins resulting table gives me only S4 to S7 and not other columns as required. Please help me
- if table1.sid = table2.sid
-
MadHatter almost 8 yearsUnfortunately, the article you link to is entirely related to init-style startup, and is thus completely irrelevant because RHEL7 is systemd-based.