在系统重新启动init 6
时,我想为我的rails项目启动我的服务,该脚本包含git的拉出更改,运行bundle install和运行延迟的作业工人
脚本位于/etc/init.d/app-startup-script
#!/bin/sh
cd /home/deploy/source/myapp
git pull origin development
bundle install
bundle exec cap staging deploy
touch /home/deploy/hello.txt (added this to test if it will create file on reboot)
然后我在重启后在crontab -e
内运行此脚本
@reboot /etc/init.d/app-startup-script
我通过使用手动运行来确认app-startup-script是否正在运行
/etc/init.d/app-startup-script
但是当我使用
重新启动系统时sudo su -
init 6
然后再次SSH到我的服务器,它仅在/ home / deploy中创建hello.txt文件,但没有启动我的Rails服务
答案 0 :(得分:0)
如果您愿意切换到systemd
服务,
您的启动脚本,
$ cat start.bash
#!/bin/bash
cd /home/deploy/source/myapp
git pull origin development
bundle install
bundle exec cap staging deploy
touch /home/deploy/hello.txt (added this to test if it will create file on reboot)
您的服务文件
$ cat yourapp.service
[Unit]
Description=Your rail app
Requires=multi-user.target
After=multi-user.target
[Service]
User=root # if it should be run as root, otherwise specify the user
ExecStart=/path/to/start.bash
[Install]
WantedBy=multi-user.target
然后做
$ chmod +x start.bash
$ cp yourapp.service /etc/systemd/system/
$ systemctl daemon-reload
$ systemctl enable yourapp.service # this should make sure, the service starts on boot