$sudo mkdir /etc/systemd/system/[email protected] 新建一個目錄
用命令在新目錄下建立一個autologin.conf文件,並加入如下內容:
$sudo nano /etc/systemd/system/[email protected]/autologin.conf
並加入如下內容:
[Service]ExecStart=ExecStart=-/usr/bin/agetty --autologin archie --noclear %I 38400 linux
archie就是要自動登陸的用戶名。
###開機自動執行一條命令
在文件夾/usr/lib/systemd/system/裏面新建一個文件example.service
內容爲:
[Unit]
Description=example
[Service]
Type=oneshot
ExecStart=/path/to/scriptfile/example.sh
[Install]
WantedBy=multi-user.target
然後設置此服務開機啓動
sudo systemctl enable example.service
此方法的好處是:
有以後需要修改命令或者添加什麼命令只用修改/path/to/scriptfile/example.sh就可以
然後自動執行程序,我用的是上面英文資料中的方法。先新建了一個文件 .bash_profile,放在(/root);;;;/home/bananapi下,然後把命令放進去,就是
有一些教程說,應該把命令添加到文件/home/bananapi/bashrc下(這裏的.bashrc是隱藏文件,要用ls -a 才能看到,其實新建的 .bash_profile也是隱藏文件,也是要用ls -a 才能看到),但是我嘗試了把命令添加到bashrc裏,實際上是不行的。後來請教ryad,才知道問題在於:.bashrc是用於交互式不需要登錄的執行腳本,而 .bash_profile是登錄進去之後的執行腳本,因爲我們已經登錄進去了,所以要執行.bash_profile文件。
最終,還是要把命令寫入到 .bash_profile,並以bananapi身份登錄,才能開機自動執行命令,打開應用。
[Unit]
Description=xiyoulibapi
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/node.js/pid
ExecStart=/usr/local/bin/forever start /node.js/xiyoulib/bin/www
ExecReload=/usr/local/bin/forever restart /node.js/xiyoulib/bin/www
ExecStop=/usr/local/bin/forever stop /node.js/xiyoulib/bin/www
PrivateTmp=true
[Install]
WantedBy=multi-user.target